I have a whole load of sort macros that are all similar to the one below and run by selecting a button on a custom toolbar. I only want certain macros to be enabled in certain worksheets to prevent errors. Is there some code I can add to each macro to check which worksheets are active before allowing the macro to run
Range("A6:GR45").Select Selection.Sort Key1:=Range("B6"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal Columns("GS:GT").EntireColumn.Hidden = True ActiveWindow.ScrollColumn = 3 Range("A1:A5").Select End Sub
try following solution [copy it to module for test and make sure that you have sheets with similar names]:
Best RegardsPublic Const inc = "Sheet1;Sheet 2;Some name" 'here sheets names you allow to run your code Sub test() t = Split(inc, ";") For i = 0 To UBound(t) If LCase(t(i)) = LCase(ActiveSheet.Name) Then check = True Exit For End If Next i If check = True Then 'here your code MsgBox ActiveSheet.Name 'example run End If End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks