VBA Hide all rows from a key row downwards.

ChrisMcIntyre

New Member
Joined
Jan 6, 2022
Messages
37
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,
Can anyone help me with the code to hide all rows downwards of a row I have a key word in please.

I have a worksheet that can have varying numbers of rows. I have hidden the word "Last" in column A301, which is the last row on the sheet in it's undedited form. What I want to do is trigger a code to hide all the rows from the one that has the word "Last" in it, downwards to the very bottom.

So as an example, if the row with the word "Last" in happens to be row 400 after the sheet has been edited (So "Last" is in A400) I need all rows from 401 to the very bottom all hidden when I click a macro button.

Hope I explained that well, apologiesif now, and I appreciate any help you can offer.
Thanks.
 
Sorry bferraz, no joy with that either. The macro ran with no bugs but everything below the row with "LAST" in is still showing.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Actually, it hid the row immediately underneath, as that is blank, but then the next rwo has something in and it appears to have stopped hiding at that point.
 
Upvote 0
Ohhh you have more rows under the Last. That is what is happening.

Please, try this one:

VBA Code:
Sub HideRows()

Dim cl As Range
Dim sh As Worksheet
Dim rng As Range

Set sh = ActiveSheet

Set cl = sh.Range("A:A").Find(What:="Last", _
            After:=sh.Cells(1, 1), _
            LookIn:=xlValues, _
            LookAt:=xlWhole, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, _
            MatchCase:=False, _
            SearchFormat:=False)
            
        If Not cl Is Nothing Then
        
        Set rng = sh.Range(cl, sh.Range("A1048576"))
        rng.EntireRow.Hidden = True
        
        End If


End Sub

It should work as it won't stop at the next filled row.
 
Upvote 0
Oh LOVELY, that worked a treat! Thanks so much bferraz, and thanks too Georgiboy, Happy New Year to you both!
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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