VB Macro hide rows

martinlemonkiss

New Member
Joined
Jul 24, 2007
Messages
3
Hi

I'm trying to write a macro which will look up a row and if in column b,c,and d all have zeros then it hides the row...the closest i can find after searching the web is below which looks up just the one column but i can't work out how to make it look up three columns other than putting a if and statement in a column and then looking up that column but i'd rather the macro did all the work

Sub HideRows()
BeginRow = 1
EndRow = 1000
ChkCol = 4


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

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the board! :)

Try this:
Code:
Sub HideRows()
Application.ScreenUpdating = False
Dim Limit As Long
Dim c As Long
Dim sh As Worksheet
Set sh = Worksheets("Sheet1")
Limit = sh.Cells(Rows.Count, 2).End(xlUp).Row
For c = Limit To 1 Step -1
     If sh.Cells(c, 2) = 0 And sh.Cells(c, 3) = 0 And sh.Cells(c, 4) = 0 Then
         sh.Rows(c).Hidden = True
     End If
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi

Thanks that worked great.

I have a number of worksheets to perform that macro on.

Is there any way i can get the macro to run through out the whole workbook or do i have to go into the macro and just change the name of the worksheet each time.
 
Upvote 0
Yup, that's no problem:
Code:
Sub HideRows()
Application.ScreenUpdating = False
Dim Limit As Long
Dim c As Long
Dim sh As Worksheet
Dim wb As Workbook
Set wb = ThisWorkbook
For Each sh In wb.Worksheets
    Limit = sh.Cells(Rows.Count, 2).End(xlUp).Row
    For c = Limit To 1 Step -1
         If sh.Cells(c, 2) = 0 And sh.Cells(c, 3) = 0 And sh.Cells(c, 4) = 0 Then
             sh.Rows(c).Hidden = True
         End If
    Next c
Next sh
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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