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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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