It's been years since I have did anything with VBA and macros and cannot figure out what I am doing wrong. I have a workbook that has multiple worksheets including a Cover Sheet, Template Sheet, and Location Sheet, as well as others. I have created specific templates on the template sheet and location sheet which pull data from the cover sheet. I have programmed the template sheet so that the sheets are blank until I generate data on the cover sheet from a data sheet at which point it populates the data in the template sheet. When I populate data and print the template sheet, it prints all 33 sheets even though there may only be 1 or 2 pages that actually display values. I have formulas that return data on the template sheet in columns A-F. Column B is my reference cell column that I am trying to use to hide or unhide the rest of the rows. The code that I attempted to create and use is below. I want it to look at cell B21 and if B21 is blank as derived from a formula ='Cover Sheet"!$A$9 due to A9 on the Cover Sheet being blank, I want rows 1-34 to be hidden and so on for the other rows. I have tried if then statements in my macros but no luck either. I know that I can use print selection to achieve what I am after but I am going to create a print button to make it easier for other users of this spreadsheet.
Private Sub Worksheet_Calculate()
Dim MyResult As String
Application.EnableEvents = False
MyResult = Worksheets("Template Sheet").Cells(21, 2).Value
Select Case MyResult
Case ""
Rows("1:34").EntireRow.Hidden = True
End Select
MyResult2 = Worksheets("Template Sheet").Cells(55, 2).Value
Select Case MyResult2
Case ""
Rows("35:68").EntireRow.Hidden = True
End Select
MyResult3 = Worksheets("Template Sheet").Cells(89, 2).Value
Select Case MyResult3
Case ""
Rows("69:102").EntireRow.Hidden = True
End Select
MyResult4 = Worksheets("Template Sheet").Cells(123, 2).Value
Select Case MyResult4
Case ""
Rows("103:136").EntireRow.Hidden = True
End Select
MyResult5 = Worksheets("Template Sheet").Cells(157, 2).Value
Select Case MyResult5
Case ""
Rows("137:170").EntireRow.Hidden = True
End Select
Application.EnableEvents = True
End Sub
Bookmarks