-
Notifications
You must be signed in to change notification settings - Fork 0
/
worksheet_exists.bas
26 lines (22 loc) · 951 Bytes
/
worksheet_exists.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Attribute VB_Name = "worksheet_exists"
Option Explicit
Public Function funcWorksheetExists(ByVal strSheetName As String) As Boolean
funcWorksheetExists = False
If strSheetName <> "" Then
Dim i As Integer
For i = 1 To Worksheets.Count
If Worksheets(i).Name = strSheetName Then
funcWorksheetExists = True
End If
Next i
End If
End Function
Private Sub TestWorksheetExists()
'Place your cursor in this procedure and click the play button.
'Make sure you have the Immediate Window showing (Ctrl + G)
Debug.Print "Worksheet named ""Sheet1"": " & funcWorksheetExists("Sheet1")
Dim strSheetName As String
strSheetName = "Sheet2"
Debug.Print "Worksheet named """ & strSheetName & """: " & funcWorksheetExists(strSheetName)
Debug.Print "Worksheet named ""SalesFigures"": " & funcWorksheetExists("SalesFigures")
End Sub