Microsoft Excel

Tuesday, October 10, 2006

Macro to check for existence of a sheet

Public Function SheetExists(ByVal sSheetName As String) As Boolean
' Returns TRUE if the sheet exists
On Error GoTo ErrHandler_SheetExists
SheetExists = False
If Sheets(sSheetName).Visible = True Or Sheets(sSheetName).Visible = False Then
SheetExists = True
End If
Exit Function
ErrHandler_SheetExists:
SheetExists = False
End Function

Wednesday, July 05, 2006

Useful Macros

Macro to Sort WorkSheets in alphabetical order

Sub Sort_Sheets()
cnt = Sheets.Count
For i = 1 To cnt - 1
For j = i + 1 To cnt
If Sheets(j).Name < Sheets(i).Name Then
Sheets(j).Move before:=Sheets(i)
End If
Next
Next
End Sub