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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Roopen

Board Regular
Joined
Apr 10, 2008
Messages
158
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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

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
 

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,079
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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

 

Watch MrExcel Video

Forum statistics

Threads
1,130,169
Messages
5,640,550
Members
417,151
Latest member
ChickenTenderer

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
Top