Summary: looping a macro through a specific array of ws. Array's name being defined in name manager. Somehow the macro loops through an additional ws which is NOT in the array.
Aim was to replace a long macro call sub for every ws I need to run the code through and learn how to use a named range array as they are dynamic.
Code is:(found it on stackoverflow then tweaked it to my purpose)
Public Sub Tester02()
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Set rng =
ActiveWorkbook.Sheets("ListOfSheets").Range("ListOfWorksheetsHRIB")
For Each SH In ActiveWorkbook.Worksheets
If Not IsError(Application.Match(SH.Name, rng, 0)) Then
Call SingleCtrRefreshHRIB
End If
Next SH
Worksheets("Dashboard").Activate
End Sub
For some reason the macro loops through an additional sheet (Sheet1= Dashboard).
In my untrained the macro goes to the "Dashboard" ws AFTER it has run through the named range. Therefore this worksheet should not included.
I can run the macro without activating the Dashboard and reposition the cursor through instructions. yet I would like to know why it does not work and learn how to restrict a macro to specifically a named range
No sure it is relevant but sub SingleCtrRefreshHRIB unprotects,refreshes a filter and protects the ws in the named range.
On a side note, I was surprised to see that the loop was not really more efficient (time-wise) than going through each individual ws. More elegant and obviously dynamic but not faster.
If needed code for the macro being called (I will clean the activate and select in this code as soon as I can).
Sub SingleCtrRefreshHRIB()
'
' In active IB worksheet macro unprotects, refreshes the "ACTIVE" 12
field and reprotects for HR
'
Application.ScreenUpdating = False
ActiveSheet.Select
ActiveSheet.Unprotect
ActiveSheet.Range("$A$1:$AB$1051").AutoFilter Field:=12
ActiveSheet.Range("$A$1:$AB$1051").AutoFilter Field:=12, Criteria1:=
_"ACTIVE"
ActiveSheet.Select
ActiveSheet.Protect DrawingObjects:=False, Contents:=True,
Scenarios:= _False, AllowFormattingColumns:=True,
AllowFiltering:=True
End Sub
thanks!