I have a workbook I use at work for putting together bids for our products and services. My estimation worksheet has 40 potential product item rows, each of which have a corresponding row on the bid worksheet (what the customer sees). I keep all but the first ten rows on the estimation sheet hidden initially, but when you fill in the 10th row, the 11th row unhides itself via VBA, and this continues until the last of the 40 rows is visible. (Up until now, I never did any hidden rows on the bid sheet; all 40 rows were always visible, I would just later manually delete rows I did not use.)
This code has worked flawlessly for years, but today, I tried to add a line to unhide the corresponding row in the bid worksheet. (I use a variable for the row number on the estimation sheet, HideRow, and one for the bid sheet, HideBRow, along with the Rows property, for the connection between the "source" row in the estimation sheet and the "destination" row in the bid sheet. They don't line up exactly, there's an offset of 15 rows between them.)
I am sure this is something academic, like I am trying to call a variable outside of the scope I'm in, but I tried this in the estimation sheet, or the ThisWorkbook module, and the part that always worked before continues to work but I can't do anything to the bid sheet. Here is the code. Thank you in advance for your help!
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim HideRow As Integer
Dim HideBRow As Integer
HideRow = 12
With ActiveWorkbook
For Each c In ActiveWorkbook.Sheets(2).Range("c12:c34") 'This is the quantity cell range, for product rows 10 and up in the estimation sheet
HideRow = HideRow + 1
HideBRow = HideRow + 15
If HideRow = 35 Then End
If IsNumeric(c.Value) Then 'If items have been entered into this row
If c.Value > 0 Then 'and it is 1 or more
If ActiveWorkbook.Sheets(2).Rows(HideRow).Hidden = True Then 'then if the next row is hidden...
ActiveWorkbook.Sheets(2).Rows(HideRow).Hidden = False 'unhide that row (this works!)
ActiveWorkbook.Sheets(20).Rows(HideBRow).Hidden = False 'this should also unhide the associated row on the bid sheet (but it's not working. 'I did a msgbox HideBRow to confirm that HideBrow has the correct row number)
Else: End If
End If
End If
Next
End With
End Sub
Bookmarks