In a large (and constantly changing) Excel file I would like to check which worksheets do have the named range “Obj_Nr”. Next step would be to run another macro only on these worksheets.
I am trying to get a list of worksheet numbers which meet the required name (like sheet 2, 3, 5 and 8).
I tried the following code:
Sub CountSheets()
Dim Counter As Range, Yc As Range
For x = 1 To ActiveWorkbook.Sheets.Count
If Worksheets(x).Names("*Obj_Nr") = True Then
If Yc Is Nothing Then
Set Yc = Counter
Else
Set Yc = Application.Union(Yc, Counter)
End If
End If
Next x
MsgBox Counter
End Sub
First I thought the problem was this NamedRange always has the worksheet name in front of it (like ‘Sheet1’!Obj_Nr and ‘Sheet2’!Obj_Nr). This would hopefully be solved by the * in front of the search term "*Obj_Nr".
Unfortunately the macro is stuck at this line:
If Worksheets(x).Names("*Obj_Nr") = True Then
Does anybody know what I am doing wrong here?
Thank you in advance.
Erik
(The Netherlands)
Bookmarks