TheFailbird
New Member
- Joined
- Oct 15, 2014
- Messages
- 12
I'm trying to create a macro that will, when printing, ignore the rows in my spreadsheet that either contain zeros or are blank; the spreadsheet is large and I don't want to print pages of rows with useless information.
I have an older version of the workbook from 2007 that contains such a macro - it's activated by a command button and works like a charm. Replicating the code in my newer version (and using Excel 2010), however, I find that the code does not function. Can anyone help me:
1. Analyze the following code and suggest probable issues?
2. Help me understand why the original author of this macro dim'd "cell" as "range"? I guess I'm trying to understand why the author expressed "cell" as Range, but simultaneously assigned "rng" as Range.
3. Explain what "Set rng = Columns(9).SpecialCells(xlFormulas, xlNumbers)" does, and why it only seems to encompass column 9, instead of the whole spreadsheet?
I am a novice and don't know that much about VBA, so please try to be concise, if possible.
P.S. I am activating the above code with a command button in my spreadsheet.
Thank you for your help!
--TheFailbird--
I have an older version of the workbook from 2007 that contains such a macro - it's activated by a command button and works like a charm. Replicating the code in my newer version (and using Excel 2010), however, I find that the code does not function. Can anyone help me:
1. Analyze the following code and suggest probable issues?
2. Help me understand why the original author of this macro dim'd "cell" as "range"? I guess I'm trying to understand why the author expressed "cell" as Range, but simultaneously assigned "rng" as Range.
3. Explain what "Set rng = Columns(9).SpecialCells(xlFormulas, xlNumbers)" does, and why it only seems to encompass column 9, instead of the whole spreadsheet?
I am a novice and don't know that much about VBA, so please try to be concise, if possible.
Code:
Sub HideRows()
Dim cell As Range, rng As Range
Cells.Rows.Hidden = False
On Error Resume Next
Set rng = Columns(9).SpecialCells(xlFormulas, xlNumbers)
On Error GoTo 0
For Each cell In rng
If cell.Value = 0 Then
cell.EntireRow.Hidden = True
End If
Next
End Sub
P.S. I am activating the above code with a command button in my spreadsheet.
Thank you for your help!
--TheFailbird--