This is weird. I have a workbook with macros working fine on Friday, Monday they don't. Behavior is it would loop through all the visible sheets, but never trigger the worksheet activate event except when I re-activate the sheet that was active when the code was triggered. Only thing I can think of is I deleted an unused sheet (Sheet2) sometime before end of day Friday. I may not have checked behavior after doing that (who knew?). I renamed the sheets so that I now have Sheet2, but that didn't fix it. It only works if I loop backwards; it might have skipped Sheet1 when looping backwards before I renamed them (don't recall).
I suppose it doesn't matter which way I loop as long as it works, but it's so weird. Can't find anything similar online. Known "undocumented behavior"? Am I doing something wrong? Sorry if this is too long, I condensed as much as I could. Thanks in advance for your help!
Here's the stripped down code:
Option Explicit Public Sub MyMacro() Dim TempSheetName As String IsRunChecks = True TempSheetName = ActiveSheet.Name WorksheetLoop IsRunChecks = False Worksheets(TempSheetName).Activate End Sub Public Sub WorksheetLoop() Dim WS_Count As Integer Dim I As Integer ' Set WS_Count equal to the number of worksheets in the active workbook. WS_Count = ActiveWorkbook.Worksheets.Count For I = WS_Count To 1 Step -1 'This works, but I had to rename the sheets from sheet3-sheet15 to sheet2-sheet14 'For I = 1 To WS_Count (this used to work until I del'd an unused worksheet which was sheet2) If Worksheets(I).Visible = True Then ' MsgBox (Worksheets(I).Name) ActiveWorkbook.Worksheets(I).Activate End If Next I End Sub
Individual sheets have this code: