Hi,
First time posting to the board. Apologies if I make any errors or break the forum etiquette.
I have a problem with some code that I have written and I am fairly new to VBA. I wrote some code so that if the cell A5 had a Yes or a No in it, then some columns would hide/unhide. (Cell A5 is a validated list) The code itself works fine. The issue is that every time that I copy and upon pasting in that sheet in another cell (say cell G16) I get:
Run-Time Error '13'
Type mismatch
Can somebody point me in the right direction? My current code is below:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$E$5" And Target = "Yes" Then
Columns("G:I").EntireColumn.Hidden = False
Columns("AI:DF").EntireColumn.Hidden = False
Columns("EG:HE").EntireColumn.Hidden = False
ElseIf Target.Address = "$E$5" And Target = "No" Then
Columns("G:I").EntireColumn.Hidden = True
Columns("AI:DF").EntireColumn.Hidden = True
Columns("EG:HE").EntireColumn.Hidden = True
End If
Application.EnableEvents = True
End Sub
Thanks Heaps
cornks
First time posting to the board. Apologies if I make any errors or break the forum etiquette.
I have a problem with some code that I have written and I am fairly new to VBA. I wrote some code so that if the cell A5 had a Yes or a No in it, then some columns would hide/unhide. (Cell A5 is a validated list) The code itself works fine. The issue is that every time that I copy and upon pasting in that sheet in another cell (say cell G16) I get:
Run-Time Error '13'
Type mismatch
Can somebody point me in the right direction? My current code is below:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address = "$E$5" And Target = "Yes" Then
Columns("G:I").EntireColumn.Hidden = False
Columns("AI:DF").EntireColumn.Hidden = False
Columns("EG:HE").EntireColumn.Hidden = False
ElseIf Target.Address = "$E$5" And Target = "No" Then
Columns("G:I").EntireColumn.Hidden = True
Columns("AI:DF").EntireColumn.Hidden = True
Columns("EG:HE").EntireColumn.Hidden = True
End If
Application.EnableEvents = True
End Sub
Thanks Heaps
cornks