ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding if Excel Sheet exists (https://www.excelbanter.com/excel-programming/366659-finding-if-excel-sheet-exists.html)

Pedro Miguel C. Silva

Finding if Excel Sheet exists
 
Hi! Can anyone tell me how to find if an Excel Sheet is already created?
Is there an instruction in VBA to make this?
For example, to look for a value in a table we have HLookup, VLookup and
Lookup. Is there an instruction for Sheets?

Thanks.

Pedro



Nick Hodge

Finding if Excel Sheet exists
 
Pedro

You could iterate over the sheets collection

Sub IterateSheets()
Dim sht As Object
For Each sht In ActiveWorkbook.Sheets
If sht.Name = "Your Sheet Name" Then
MsgBox "Sheet found"
sht.Activate
Exit Sub
End If
Next sht
MsgBox "Sheet not found"
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"Pedro Miguel C. Silva" wrote in message
...
Hi! Can anyone tell me how to find if an Excel Sheet is already created?
Is there an instruction in VBA to make this?
For example, to look for a value in a table we have HLookup, VLookup and
Lookup. Is there an instruction for Sheets?

Thanks.

Pedro




Bob Phillips

Finding if Excel Sheet exists
 

On Error Resume Next
Set ws = Worksheets("some sheet")
On Error Goto 0
If Not ws Is Nothing Then
MsgBox "sheet already exists"
End If

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Pedro Miguel C. Silva" wrote in message
...
Hi! Can anyone tell me how to find if an Excel Sheet is already created?
Is there an instruction in VBA to make this?
For example, to look for a value in a table we have HLookup, VLookup and
Lookup. Is there an instruction for Sheets?

Thanks.

Pedro






All times are GMT +1. The time now is 07:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com