Guess this is all you need.
Put it in ThisWorkbook.
Private Sub Workbook_NewSheet(ByVal Sh As Object)
'Create a Named Range to refer to in Workbook_SheetChange procedure
'Named Ranges refer to Workorder rows in the sheet Annual Report and are created upon inserting a new workorder sheet
'Named Ranges must comply to the name convention: "AnRepWO" + Workorder number
WoNum = 0
For Each NamedRange In ActiveWorkbook.Names
If Left(NamedRange.Name, 7) = "AnRepWO" Then
WoNum = WorksheetFunction.Max(WoNum, Replace(NamedRange.Name, "AnRepWO", "")) 'select the highest existing workorder number
End If
Next NamedRange
NextWoNum = WoNum + 1 'WoNum will be the highest existing workorder number
Set NewRange = Worksheets("Annual Report").Range("AnRepWO" & WoNum).Offset(4, 0) 'Assuming there are always 4 rows for a workorder
ActiveWorkbook.Names.Add Name:="AnRepWO" & NextWoNum, RefersTo:=NewRange 'Create new named range
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Sh.Range("A5")) Is Nothing Then 'Limit the changes to be processed
'Use a named range to refer to the worksorder rows in the sheet Annual Report to be hidden or shown
If LCase(Target.Value) = "not started" Then
Range("AnRep" & Sh.Name).EntireRow.Hidden = True 'Hide the rows for the workorder represent by the sheet changed
Else
Range("AnRep" & Sh.Name).EntireRow.Hidden = False 'Show the rows for the workorder represent by the sheet changed
End If
End If
End Sub
This solution, however, requires you to name your sheets consistently (WO1, WO2, WO3 etc), but that shouldn't be a problem
Bookmarks