Hide all rows below specific text in cell

Cooki

Board Regular
Joined
Jul 31, 2018
Messages
86
I need to hide all rows under "Total" in column B

Got a macro to delete blank rows between the last cell with data and Total, but every time it deletes the hidden cells under total appear, very annoying

Sub HideRowsBelow()

Application.ScreenUpdating = True
Dim mainshseet As Worksheet
Set mainsheet = ActiveWorkbook.Worksheets("Q2")

Dim fRg As Range
Dim lr, i As Long
lr = mainsheet.Cells(Rows.Count, "B").End(xlUp).Row
Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
For i = lr To (fRg.Row + 1) Step -1
mainsheet.Cells(i, 1).EntireRow.Hide
Next i

End Sub

Can anyone solve this for me please?

792EDQ V Fuse : .Janette MorrisHHDC
Total
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
In that case you did not do what I said, if you had there would not be a Next to give an error & you would have
VBA Code:
Sub DeleteRowsBelow()
  
   Application.ScreenUpdating = True
   Dim mainshseet As Worksheet
   Set mainsheet = ActiveWorkbook.Worksheets("Q2")
  
   mainsheet.Unprotect Password:="retsup#qu2021"

   Dim fRg As Range
   Dim lr, i As Long

   Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
   fRg.Offset(1).Resize(Rows.Count - fRg.Row).EntireRow.Hidden = True

   mainsheet.Protect Password:="retsup#qu2021", AllowFiltering:=True, AllowSorting:=True
End Sub
 
Upvote 0
In that case you did not do what I said, if you had there would not be a Next to give an error & you would have
VBA Code:
Sub DeleteRowsBelow()
 
   Application.ScreenUpdating = True
   Dim mainshseet As Worksheet
   Set mainsheet = ActiveWorkbook.Worksheets("Q2")
 
   mainsheet.Unprotect Password:="retsup#qu2021"

   Dim fRg As Range
   Dim lr, i As Long

   Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
   fRg.Offset(1).Resize(Rows.Count - fRg.Row).EntireRow.Hidden = True

   mainsheet.Protect Password:="retsup#qu2021", AllowFiltering:=True, AllowSorting:=True
End Sub
I do apologies, i defo miss understood.

ran that and get run time error '9' Subscript out of range
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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