Hi Community,
I am using Excel 2010.
I am trying to Hide/Unhide rows when specific cells are selected in a Worksheet. I have managed to do so with the following code:
As you see, I have defined two ranges (UnHideRange and HideRange) that define the cells that trigger the macros. Both ranges are repeated every 11 rows in the same columns. For example, HideRange would refer to cells G17, G28, G39, G50.... and UnhideRange would refer to C16:E16, c27:e27, C38:E38,c49:e49...
I do not want to enter manually all the ranges for two reasons:
I would like to set the Range HideRange saying "it starts at cell G17 and then continues every 11 rows in the same column until row 500". The same for UnHideRange.
Is this possible?
Thank you in advance.
Best,
Daniel
I am using Excel 2010.
I am trying to Hide/Unhide rows when specific cells are selected in a Worksheet. I have managed to do so with the following code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim UnHideRange As Range
Dim HideRange As Range
Set UnHideRange = Range("C16:E16,c27:e27")
Set HideRange = Range("G17,G28")
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Target, HideRange) Is Nothing Then Call Hide10Cells
If Not Application.Intersect(Target, UnHideRange) Is Nothing Then Call Show10Cells
End Sub
As you see, I have defined two ranges (UnHideRange and HideRange) that define the cells that trigger the macros. Both ranges are repeated every 11 rows in the same columns. For example, HideRange would refer to cells G17, G28, G39, G50.... and UnhideRange would refer to C16:E16, c27:e27, C38:E38,c49:e49...
I do not want to enter manually all the ranges for two reasons:
- They are a lot
- If I add one row I would need to change everything manually
I would like to set the Range HideRange saying "it starts at cell G17 and then continues every 11 rows in the same column until row 500". The same for UnHideRange.
Is this possible?
Thank you in advance.
Best,
Daniel