Excel Code to Hide VBA rows based on Criteria

Youseepooo

New Member
Joined
Feb 5, 2019
Messages
37
Hey i have this code that i use to sort my worksheet however i want to include a special provision where if the text in the Range of column "C" equals "TOTAL" do not hide the empty row under it.

For example i want the worksheet to have a row separating my tables after the, text TOTAL.

Right now it hides every row with a empty space in the range but i want to not hide the row if the cell above that CURRENT cell reads "TOTAL"

this is the code :

Code:
Dim xRg As Range Application.ScreenUpdating = False
For Each xRg In Range("C3:C420")
If xRg.Value = "" Then
xRg.EntireRow.Hidden = True
Else
xRg.EntireRow.Hidden = False
End If
Next xRg
Application.ScreenUpdating = True
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Possibly...
Code:
Range("C3:C420").SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
For Each xRg In Range("C3:C420")
    If xRg.Value = "Total" Then xRg.Offset(1, 0).EntireRow.Hidden = False
Next xRg
 
Last edited:
Upvote 0
Solved:

Application.ScreenUpdating = False

For Each xRg In Range("C3:C420")
If xRg.Value = "" Then
If xRg.Offset(-1, 0).Value <> "TOTAL" Then
xRg.EntireRow.Hidden = True
End If
End If
Next xRg

Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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