I had found some code about hiding and unhiding cells based on specific entry in another cell which I have changed to hopefully fit my needs.
My problem is that when I try to run it from the VBA screen it asks me to name it in the Macros Name screen. If I type in the name and click create, it takes back to VBA with just the shell code. If I paste the code into that shell and try to run it, I'm back to the Macro naming screen.
I'm sure I'm doing something stupid, but I've searched on everything I think is logical. Any help would be very appreciated it. Thank you for your help and for all the other help you have unknowingly been providing.
Here is the code I'm using:
Private Sub Worksheet_Change(ByVal Target As Range)
'Hide cells based on entry in Column E, column E is chosen from a drop down list
If WorksheetFunction.CountIf(Columns(5), 1) = 1 Then
Columns("H:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 2 Then
Columns("J:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 3 Then
Columns("L:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 4 Then
Columns("N:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 5 Then
Columns("F:O").Hiddent = False
Else
Columns("H:O").Hidden = True
End Sub
My problem is that when I try to run it from the VBA screen it asks me to name it in the Macros Name screen. If I type in the name and click create, it takes back to VBA with just the shell code. If I paste the code into that shell and try to run it, I'm back to the Macro naming screen.
I'm sure I'm doing something stupid, but I've searched on everything I think is logical. Any help would be very appreciated it. Thank you for your help and for all the other help you have unknowingly been providing.
Here is the code I'm using:
Private Sub Worksheet_Change(ByVal Target As Range)
'Hide cells based on entry in Column E, column E is chosen from a drop down list
If WorksheetFunction.CountIf(Columns(5), 1) = 1 Then
Columns("H:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 2 Then
Columns("J:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 3 Then
Columns("L:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 4 Then
Columns("N:O").Hidden = True
If WorksheetFunction.CountIf(Columns(5), 1) = 5 Then
Columns("F:O").Hiddent = False
Else
Columns("H:O").Hidden = True
End Sub