A Macro to Hide Rows

Roopen

Board Regular
Joined
Apr 10, 2008
Messages
158
Hi

I am in need of a macro that will hide the rows if the total of a given row is zero in Column M.

I would ultimately want this macro to be activated using a button. (which I know how to add)

Any help on the code would be of huge help!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Code:
Sub test()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("M" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Rows(i).Hidden = Range("M" & i).Value = 0
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try

Code:
Sub test()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("M" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    Rows(i).Hidden = Range("M" & i).Value = 0
Next i
Application.ScreenUpdating = True
End Sub

Hi Peter, A quick problem... When I run the macro it also hides the top 10 rows that have no data in... How do I change this code so it actually only supresses zero values from column M from row 11 to 31?

Many thanks
 
Upvote 0
Just change the 1 to 11

Rich (BB code):
Sub test()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("M" & Rows.Count).End(xlUp).Row
For i = 11 To LR
    Rows(i).Hidden = Range("M" & i).Value = 0
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Peter, A quick problem... When I run the macro it also hides the top 10 rows that have no data in... How do I change this code so it actually only supresses zero values from column M from row 11 to 31?

Many thanks

Replace For i=1 to LR with For i = 11 to 31

 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,788
Members
449,049
Latest member
greyangel23

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