VBA Code - Unhide block of rows

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi,

Currently I have a code which unhides the row below if cell J45 is populated.
However, I would like it to unhide a block of rows. So instead of just unhiding 1 row below, it unhides 21 rows below (rows 46:66). Is there anyway to amend this code to do that?



Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("J45:J45")) Is Nothing And Target.Cells.Count = 1 Then
        Target.Offset(1).EntireRow.Hidden = Target.EntireRow.Hidden
    End If
End Sub

Thanks.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$J$45" Then
    Target(2).Resize(21).EntireRow.Hidden = False
End If
End Sub
 
Last edited:
Upvote 0
Hi,

Currently I have a code which unhides the row below if cell J45 is populated.
However, I would like it to unhide a block of rows. So instead of just unhiding 1 row below, it unhides 21 rows below (rows 46:66). Is there anyway to amend this code to do that?

Thanks.

Code:
Target.Offset(1).resize(21).EntireRow.Hidden = False

Edit looks like I was late in submitting my post
 
Last edited:
Upvote 0
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  7/22/2019  10:50:50 PM  EDT
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = Range("J45").Address Then Rows(Target.Row).Offset(1).Resize(21).Hidden = False
End Sub
 
Upvote 0
If you want to Toggle those rows from Hidden to Visible.
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  7/22/2019  11:31:57 PM  EDT
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
If Target.Address = Range("J45").Address Then Target(2).Resize(21).EntireRow.Hidden = Not Target(2).Resize(21).EntireRow.Hidden
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

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