Home
xlite's excel blogs
Recent Entries 
Sub WindowExplorer()
Shell "c:\windows\explorer.exe c:\program files"
End Sub
22nd-Mar-2006 10:49 pm - Freeze panes
this code freezes all worksheets with the word freeze in them:

Sub FreezeMe()
Dim ws As Worksheet
For Each ws In Worksheets

ActiveWindow.FreezePanes = True 'unfreeze existing panes
'find the word freeze
Cells.Find(What:="freeze", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

ActiveWindow.SplitRow = ActiveCell.Row - 1 'split row
ActiveWindow.SplitColumn = ActiveCell.Column - 1 'split column
ActiveWindow.FreezePanes = True 'freeze panes
Next 'on to the next sheet
End Sub
24th-Jan-2006 10:16 pm - List Workbooks and Worksheets
Sub myBooks()
Dim i As Integer, s As Integer
Cells.Clear
For i = 1 To Application.Workbooks.Count
Range("A65536").End(xlUp).Offset(1, 0) = Workbooks(i).Name
For s = 1 To Application.Worksheets.Count
Range("A65536").End(xlUp).Offset(1, 0) = Workbooks(i).Sheets(s).Name
Next
Next
End Sub

to include the filepath just add: Workbooks(i).FullName
14th-Jan-2006 09:30 am - Insert Page Breaks With Criteria
Sub ColCBreaks()
ActiveSheet.ResetAllPageBreaks
For Each Cell In Range("C6", Range("C65536").End(xlUp)) 'header in row 4
If Cell.Value <> Cell.Offset(-1, 0) Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cell
End If
Next
ActiveSheet.PageSetup.Zoom = 100
End Sub
14th-Jan-2006 09:12 am - Insert Page Breaks
Sub InsertBreaks()
Dim r As Integer
r = Int(ActiveSheet.UsedRange.Rows.Count / 32)

ActiveSheet.ResetAllPageBreaks

For r = 1 To r
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cells(r * 32 + 1, 1)
Next r

End Sub
5th-Jan-2006 11:24 pm - Access the Web from Excel
Using a userform and a textbox, assign the code below to a commandbutton:

Private Sub CommandButton1_Click()
Dim strLink As String
straddress = "http://www." & Me.TextBox1
ActiveWorkbook.FollowHyperlink straddress, , True
End Sub
5th-Jan-2006 11:05 pm - Do-While Loop
The code below is an example of a do-while loop within another do-while loop.


Sub ConditionalSum()
Application.ScreenUpdating = False 'speed up code
Range("C2:D65536").Clear ' clear prev results

Range("C2").Select 'starting cell
Do Until IsEmpty(ActiveCell.Offset(0, -1).Value) ' do until last cell
lReturnSum = 0 'start with zero
Do Until ActiveCell.Offset(0, -2).Value <> ActiveCell.Offset(1, -2).Value 'do until a different date is found
lReturnSum = lReturnSum + ActiveCell.Offset(0, -1).Value 'add values of same dates
'count occurances of a date
numwords = Application.CountIf(Sheets("Sheet1").Range("A2", Range("A65536").End(xlUp)), ActiveCell.Offset(0, -2).Value)
ActiveCell.Offset(1, 0).Select 'select next cell below
Loop
lReturnSum = lReturnSum + ActiveCell.Offset(0, -1).Value 'sum
ActiveCell.Value = lReturnSum 'write the sum
ActiveCell.Offset(0, 1).Value = ActiveCell.Value / numwords 'write divided value
ActiveCell.Offset(1, 0).Select 'select next cell below
Loop
Application.ScreenUpdating = True
End Sub
27th-Dec-2005 07:28 pm - Custom Menubar
Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("MyCommandbar").Delete
On Error Goto 0
End Sub

Private Sub Workbook_Open()

On Error Resume Next
Application.CommandBars("MyCommandbar").Delete
On Error Goto 0

With Application.CommandBars.Add(Name:="MyCommandbar", Temporary:=True)
With .Controls.Add(Type:=msoControlButton)
.OnAction = "The Procedure_Name when clicking on the button"
.FaceId = 343
.TooltipText = "Text to show when hovering over the button"
End With
.Position = msoBarFloating
.Visible = True
End With

End Sub
26th-Dec-2005 11:39 pm - Days in Current Week
The following formula returns the Monday of the current week:
=TODAY()-(WEEKDAY(TODAY())-2)

carrying it on, this gives Tuesday:
=TODAY()-(WEEKDAY(TODAY())-3)

and so on until Sunday:
=TODAY()-(WEEKDAY(TODAY())-8)

this formula is dependent upon how you set the computer calendar's first day.
my formula's are based on Sunday as the first day of the week.
In some cases more efficient and easier to draw up than a userform.
One such case is the display of a live chart, just copy and paste a chart
into the dialog sheet.

To create, right-click on the sheet tab and Insert - MS Excel 5.0 Dialog.



The Forms toolbar automatically appears and you can add controls as you like just as in VBE.

Notice the "Light Switch" on the toolbar. This is to show the Dialog much like the userform's
me.show.
I recorded a macro while swicthing on the DialogSheet and this came up:
DialogSheets("Dialog1").Show

You don't even need to know the macro to unload it as it automatically comes with an OK and a Cancel button.
This page was loaded Nov 28th 2009, 1:29 pm GMT.