OK, assuming that cell H2 allows numeric entries only from 1 to 9 (which you can control with Data Validation), put this code on your Details sheet:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rws As String
Dim cls As String
' Only run if one cell updated
If Target.CountLarge > 1 Then Exit Sub
' See what cell was update
Select Case Target.Address
' Check cell H2
Case "$H$2"
' First unhide all columns
Sheets("Pricing").Columns("K:S").EntireColumn.Hidden = False
' Get first column to hide, depending on value in H2
cls = Chr(74 + Target.Value)
' Hide columns on pricing sheet
Sheets("Pricing").Columns(cls & ":S").EntireColumn.Hidden = True
' Check to see if B21 was updated
Case "$B$21"
rws = "8:15"
' Check to see if B22 was updated
Case "$B$22"
rws = "16:33"
' Check to see if B23 was updated
Case "$B$23"
rws = "34:48"
' continue on for cells B24-B32
' ...
' ...
' Check to see if B23 was updated
Case "$B$33"
rws = "161:166"
End Select
' Check to see if rws updated
If rws <> "" Then
Select Case Target.Value
Case "Yes"
Sheets("Pricing").Rows(rws).EntireRow.Hidden = False
Case "No"
Sheets("Pricing").Rows(rws).EntireRow.Hidden = True
End Select
End If
End Sub
Note that since there is no distinct pattern in how many rows to hide, you will need a separate Case clause for each cell in B21:B33. I did B21-B23 and B33 for you. You can fill in the rest. Just follow the same method I did for the first three. The spots with the "..." is where you will want to insert that.
Thanks a million for the quick turnaround with the help.
I must be doing something wrong though.
It is hiding the columns perfectly but it's not making any difference to the rows.
Here's the code I entered:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rws As String
Dim cls As String
' Only run if one cell updated
If Target.CountLarge > 1 Then Exit Sub
' See what cell was update
Select Case Target.Address
' Check cell H2
Case "$H$2"
' First unhide all columns
Sheets("Pricing").Columns("K:S").EntireColumn.Hidden = False
' Get first column to hide, depending on value in H2
cls = Chr(74 + Target.Value)
' Hide columns on pricing sheet
Sheets("Pricing").Columns(cls & ":S").EntireColumn.Hidden = True
' Check to see if B21 was updated
Case "$B$21"
rws = "8:15"
' Check to see if B22 was updated
Case "$B$22"
rws = "16:33"
' Check to see if B23 was updated
Case "$B$23"
rws = "34:48"
' Check to see if B24 was updated
Case "$B$24"
rws = "49:61"
' Check to see if B25 was updated
Case "$B$25"
rws = "62:75"
' Check to see if B26 was updated
Case "$B$26"
rws = "76:98"
' Check to see if B27 was updated
Case "$B$27"
rws = "99:120"
' Check to see if B28 was updated
Case "$B$28"
rws = "121:126"
' Check to see if B29 was updated
Case "$B$29"
rws = "127:139"
' Check to see if B30 was updated
Case "$B$30"
rws = "140:147"
' Check to see if B31 was updated
Case "$B$31"
rws = "148:154"
' Check to see if B32 was updated
Case "$B$32"
rws = "155:160"
' Check to see if B33 was updated
Case "$B$33"
rws = "161:166"
End Select
' Check to see if rws updated
If rws <> "" Then
Select Case Target.Value
Case "Yes"
Sheets("Pricing").Rows(rws).EntireRow.Hidden = False
Case "No"
Sheets("Pricing").Rows(rws).EntireRow.Hidden = True
End Select
End If
End Sub
I noticed that the last Case clause that you had written had B23 rather than B33 so I changed it.
I also tried it as written but that didn't make any difference either.
Would it make a difference if I had the Yes/No in B21:B33 selected by data validation or not?
At the moment it is data validation