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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Are you trying to hide every single row from Total to row 1,048,576?
 
Upvote 0
Are you trying to hide every single row from Total to row 1,048,576?
the rows are already hidden, but each time i delete for example 5 rows that are blank, 5 rows unhide under total

if that makes sence
 
Upvote 0
Ok, how about
VBA Code:
Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
fRg.Offset(1).Resize(Rows.count - fRg.Row).EntireRow.Hidden = True
 
Upvote 0
Ok, how about
VBA Code:
Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
fRg.Offset(1).Resize(Rows.count - fRg.Row).EntireRow.Hidden = True
Im getting compile error "next without for"

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
lr = mainsheet.Cells(Rows.Count, "B").End(xlUp).Row 'Assumes rowdata existsin column A
Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
fRg.Offset(1).Resize(Rows.Count - fRg.Row).EntireRow.Hidden = True
mainsheet.Cells(i, 1).EntireRow.Hide
Next i
mainsheet.Protect Password:="retsup#qu2021", AllowFiltering:=True, AllowSorting:=True
End Sub
 
Upvote 0
Remove these two lines
VBA Code:
mainsheet.Cells(i, 1).EntireRow.Hide
Next i
 
Upvote 0
Remove these two lines
VBA Code:
mainsheet.Cells(i, 1).EntireRow.Hide
Next i
Ah the FOR has been taken out, ive added it back in back guess thats incorrect as not working

Sub hideRowsBelow()

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
lr = mainsheet.Cells(Rows.Count, "B").End(xlUp).Row 'Assumes rowdata existsin column A
Set fRg = mainsheet.Cells.Find(what:="Total", lookat:=xlWhole)
fRg.Offset(1).Resize(Rows.Count - fRg.Row).EntireRow.Hidden = True
For i = lr To (fRg.Row + 1) Step -1
mainsheet.Cells(i, 1).EntireRow.Hide
Next i
mainsheet.Protect Password:="retsup#qu2021", AllowFiltering:=True, AllowSorting:=True
End Sub
 
Upvote 0
Why are you adding stuff back & ignoring what I said?
 
Upvote 0
Why are you adding stuff back & ignoring what I said?


Apologies but It has a next i

so required a FOR to be in there?

apolgies if im wrong, but thats what the errors is saying, even when i just put in what you suggested?
 
Upvote 0
Apologies but It has a next i

so required a FOR to be in there?

apolgies if im wrong, but thats what the errors is saying, even when i just put in what you suggested?
Just doubled and checked and get the same error - Compile Error "Next without For"

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)
fRg.Offset(1).Resize(Rows.Count - fRg.Row).EntireRow.Hidden = True
mainsheet.Cells(i, 1).EntireRow.Hide
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
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