Zero Value Macro

MichaelWayne_71

Board Regular
Joined
Nov 9, 2005
Messages
60
Hi all,
I have seen a macro b4 that, when clicked, hid all of the ROWS with a zero value. I cannot get the sheet unlocked to figure out how they did it. I am okay in excel with formulas but, just starting with VBA and am very weak with it.

e.g.--I create sales proposals from hundreds of different products. Some
values will change automatically based on selection in another (a cable
that is required for a printer, etc...) I would like to be able to shrink
the list before I print it out without having to hide all rows that list
products that do not pertain to their proposal.

Detailed help would be appreciated!!! :biggrin:

Thank you!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Welcome to MrExcel - if you mean, hide all rows having zero in column X, you can apply autofilter with Custon of not equal 0.
 
Upvote 0
Not sure custom filter will work

Not sure I can use custom filter because I have headings in each category that are in different Columns.

e.g.
A B C D
Backoffice Hardware
row 1 quantity p/n description price
row 2
row 3
row 4

Communications Hardware
etc...
 
Upvote 0
If you are looking for something that hides rows where all values are zero, try something like this:

Sub HideIt()
Dim cell As Range
Cells.EntireRow.Hidden = False
Range("A1:A" & [a65536].End(xlUp).Row).Select
For Each cell In Selection
If cell.Offset(0, 1).Value = 0 And cell.Offset(0, 2).Value = 0 And cell.Offset(0, 3).Value = 0 And cell.Offset(0, 4).Value = 0 Then cell.EntireRow.Hidden = True
Next cell
End Sub
 
Upvote 0
1. Press Alt-F11 to open VBA
2. Choose "Module" from the "insert" menu
3. Double-click "module 1" in the left pane
4. In the right pane, paste in the macro.
5. Close VBA

To get a button:
1. From the view menu, choose toolbars then forms.
2. Click on the button
3. Drag it on your worksheet
4. Choose the macro to assign (the one called HideIt)
 
Upvote 0
Sure:

Change the "A" in the line below to the column you want:
Range("A1:A" & [a65536].End(xlUp).Row).Select

Then replace:
cell.Offset(0, 1).Value = 0 And cell.Offset(0, 2).Value = 0 And cell.Offset(0, 3).Value = 0 And cell.Offset(0, 4).Value = 0
with
cell.value

If this is the case (only one column), I would probably skip the macro and use an autofilter.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

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