Hello
I'm trying to add onto some existing code, a further step that will hide columns - I think a slightly modified requirement to those I've seen when looking through the forum.
I've created a sub routine called 'HideColumns', which works when run on its own:
But I'm having difficulty in working out how to call the routine from the private sub. The code that I have so far (3rd section) is as follows and I'm wanting it to run, should there be a change to any of the cells in the range (Y9 to AZ27)
As ever - any help would be much appreciated.
Thanks
David
I'm trying to add onto some existing code, a further step that will hide columns - I think a slightly modified requirement to those I've seen when looking through the forum.
I've created a sub routine called 'HideColumns', which works when run on its own:
VBA Code:
Sub HideColumns()
'Hide columns until they are needed
Dim c As Range
For Each c In Range("AA1:AZ1").Cells
If c.Value = "NoShow" Then
c.EntireColumn.Hidden = True
ElseIf c.Value = "Show" Then
c.EntireColumn.Hidden = False
End If
Next c
End Sub
But I'm having difficulty in working out how to call the routine from the private sub. The code that I have so far (3rd section) is as follows and I'm wanting it to run, should there be a change to any of the cells in the range (Y9 to AZ27)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Selection of the shop name returns the post code and telephone number (if available)
If Target.Address = "$Q$5" Then
Application.EnableEvents = False
Call getdata
Application.EnableEvents = True
' Change to Y5 results in rows being hidden
ElseIf Target.Address = "$Y$5" Then
Application.EnableEvents = False
Call HideRows
Application.EnableEvents = True
' Change to any of the cells in the range results in the columns being hidden
ElseIf Target.Address = "$Y$9:$AZ$27" Then
Application.EnableEvents = False
Call HideColumns
Application.EnableEvents = True
End If
End Sub
As ever - any help would be much appreciated.
Thanks
David