Hide rows with specific values on all sheets

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
365
Greetings,

I found this code I believe through MrExcel and am wondering how I can conduct this search on all worksheets, not just one?

VBA Code:
    BeginRow = 1
    EndRow = 300
    ChkCol = 1

    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "HIDE" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt

Thanks!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This should do what you need....BUT...you haven't supplied ALL of the code, so there may be other issues !!!
VBA Code:
Sub MM1()
Dim ws As Worksheet
Application.ScreenUpdating = False
 BeginRow = 1
    EndRow = 300
    ChkCol = 1
For Each ws In Worksheets
    ws.Activate
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "HIDE" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt
Next ws
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I suspect you want to find all values in Column A of all sheets.
Not just rows 1 to 300 as each sheet may not have the same number rows.
So try this:
VBA Code:
Sub Hide_Rows()
'Modified 3/24/2020 12:09:22 AM EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim b As Long
For i = 1 To Sheets.Count
With Sheets(i)
Lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For b = 1 To Lastrow
If .Cells(b, 1).Value = "Hide" Then .Rows(b).Hidden = True
Next
End With
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
@MAIT
The OP has advised that he is using Col "A" in his code snippet
VBA Code:
BeginRow = 1
EndRow = 300
ChkCol = 1
 
Upvote 0
@MAIT
The OP has advised that he is using Col "A" in his code snippet
VBA Code:
BeginRow = 1
EndRow = 300
ChkCol = 1
That what my script is doing:
If .Cells(b, 1).Value = "Hide" Then .Rows(b).Hidden = True
 
Upvote 0
But you stated
Rich (BB code):
I suspect you want to find all values in Column A of all sheets.
which he has already alluded to !
 
Upvote 0
But you stated
Rich (BB code):
I suspect you want to find all values in Column A of all sheets.
which he has already alluded to !
Michael, I think you need to read that line with an emphasis on the word "all" and in conjunction with what followed. MAIT's point was about whether every sheet would have 300 rows or not, rather than what columns were to be used.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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