Check If Multiple Sheets Exist

WorkMC

Board Regular
Joined
Jul 21, 2005
Messages
88
I have two workbooks open, the first is a summary, the second has new data that needs transferring into the summary. Before transferring the data I need to check that 10 specific sheets exist in the file with the new data.

I have found some code that checks for one sheet name, but really need to check for 10 specific names, if any are missing then I need a message to appear, listing the missing ones and stopping the macro from proceeding, cany anyone help?


Dim mySheetName As String, mySheetNameTest As String

ActiveWindow.ActivateNext
mySheetName = "Data"
On Error Resume Next
mySheetNameTest = Worksheets(mySheetName).Name
If Err.Number = 0 Then
MsgBox "The sheet named ''" & mySheetName & "'' DOES exist in this workbook."
Else
Err.Clear
MsgBox "The sheet named ''" & mySheetName & "'' does NOT exist in this workbook."
End If
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe a way would be to add a sheet to the data workbook & list all worksheet names which the code below will do, then list the names needed & match to check if any are missing.

Code:
Sub SheetNames()
    
    Sheets.Add.Name = ("ws names")
    
    For i = 1 To Sheets.Count
        Cells(i, 1) = Sheets(i).Name
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top