Hide Entire Row based on cell equalling "Zero" using a Command Button

D_Spark

Board Regular
Joined
Feb 4, 2007
Messages
232
Can someone please assist?

i have a very large workbook with some 200+ rows, (column c4:c220) contain a numberic value.

I want a commandbutton when clicked to hide any row where the c column value for that particular row equals zero

eg

If

c4=1
c5=0
c6=2
c7=0
c8=12
c9-11
c10=1
c12=0

when CommandButton1_Click() rows (5,7,and 12) will all be hidden

I also want a code so that when CommandButton2_Click() is pressed all rows c4:c200 are unhidden
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

Code:
Private Sub CommandButton1_Click()
Dim c As Range
For Each c In Range("C4:C200")
    c.EntireRow.Hidden = c.Value = 0
Next c
End Sub

Private Sub CommandButton2_Click()
Rows("4:200").Hidden = False
End Sub
 
Upvote 0
VOG Thanks for the code that works great. How would I modify the code to use a named range instead of specific row numbers. This way the vba will grow as the user adds new rows into the range.
Thanks
Rob
 
Upvote 0
VOG Thanks for the code that works great. How would I modify the code to use a named range instead of specific row numbers. This way the vba will grow as the user adds new rows into the range.
Thanks
Rob

Try like this

Code:
Private Sub CommandButton1_Click()
Dim c As Range
For Each c In Range("MyRange")
    c.EntireRow.Hidden = c.Value = 0
Next c
End Sub

Private Sub CommandButton2_Click()
Range("MyRange").EntireRow.Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

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