VBA Code - Unhide block of rows

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
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.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,030
Office Version
2016
Platform
Windows
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:

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
350
Office Version
2016
Platform
Windows
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:

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,762
Office Version
2013
Platform
Windows
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,762
Office Version
2013
Platform
Windows
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
 

tlc53

Active Member
Joined
Jul 26, 2018
Messages
365
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
Thank you! This did the trick :)
 

Watch MrExcel Video

Forum statistics

Threads
1,101,756
Messages
5,482,698
Members
407,358
Latest member
Maze123

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top