Hide / Unhide Rows based on what another row is doing

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

I've got an idea but I don't have the technical ability to write it nor do I know if it's possible.
Hiding rows based on a change of a formulated cell is not easy to do. In this particular example though, the data is manually entered up top and summarised down the bottom by formulas. I have this nifty code up top which adds a line one at a time, as needed by the user;


Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range
Set Rng = Intersect(Target, [B21:B116])
If Not Rng Is Nothing Then Rng(2, 1).EntireRow.Hidden = False
End Sub

For the summary below which is completely formulated referring to the manual data entered above, is it possible to hide a row, if another row is hidden. For example, if row 21 is hidden, hide row 138. If row 22 hidden, hide row 139.

If hidden:.....Hide
Row 21........Row 138
Row 22........Row 139
Row 23........Row 140
Row 24........Row 141
All the way down to..
Row 116......Row 233

It would also need to work the other way round, so it shows when visible.

Thank you for your time!
 
I think it's me, as I've not explained myself clearly and probably said the wrong thing.

I'm going to try and explain it again.

Range B21:B116 are data entry cells. When B21 is populated, rows 22 (B22) and 139 should unhide.

Cell Populated.....Rows Unhide
B21...................22 and 139
B22...................23 and 140
B23...................24 and 141
B24...................25 and 142
All the way down to...
B115.................116 and 233

So there's 117 lines inbetween the first row unhiding and the next. Hopefully this makes more sense. Really sorry about the confusion!!
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Then how about this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("B21:B115")) Is Nothing And Target.Cells.Count = 1 Then
        Target.Offset(1).EntireRow.Hidden = Target.EntireRow.Hidden
        Target.Offset(117).EntireRow.Hidden = Target.EntireRow.Hidden
    End If

End Sub

Note: How do you enter the data in Range B21:B115? If it is by formula then the code won't work.
 
Upvote 0
You've done it!! Thank you very much Akuini!

And thank you too Michael M. Sorry again for any confusion.

Really appreciate all the help!!
 
Upvote 0
You've done it!! Thank you very much Akuini!

And thank you too Michael M. Sorry again for any confusion.

Really appreciate all the help!!

You're welcome, glad to help, & thanks for the feedback.:)

Minor correction: in the code the range should be
Range("B21:B116") not Range("B21:B115")

so please change it.
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,041
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top