Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find if Worksheet Name exists in Active Workbook through VBA? 2

Status
Not open for further replies.

logius

Programmer
Aug 30, 2001
175
US
Anyone know of a method for checking if a particular worksheet name exists in a workbook. I know it'll probably use the Worksheets.Name property, but the actual code for searching is eluding me.

----------------------------------------
If you are reading this, then you have read too far... :p
 
This may be a sloppy approach but why not use a combination of On Error and worksheets(<ws_name>).activate?

_________________
Bob Rashkin
 
Dim i as Integer
For i = 1 to Worksheets.Count
msgbox(Sheets(i).Name)
Next

I hope this helps.

Ron

Ron Repp
 

If WorkSheetExists("<name here") Then

.....

Function WorkSheetExists(ByVal strWorkSheetName As String) As Boolean
Dim aWorkSheet As WorkSheet
WorkSheetExists = False
For Each aWorkSheet In ActiveWorkBook.WorkSheets
If LCase(strWorkSheetName) = LCase(aWorkSheet.Name) Then
WorkSheetExists = True
Exit For
End If
Next
End Function
 
Oh, that's perfect, mrmovie. Thanks!

----------------------------------------
If you are reading this, then you have read too far... :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top