URGENT!! Use macro button to hide empty columns and rows...HELP!!!
Your macro says it's purpose is to hide columns with no data in rows 10:82
but actually checks rows 4:8. Change the line:
If Application.Count(Range(Cells(4, col.Column), Cells(8, col.Column))) = 0
Then
to read
If Application.Count(Range(Cells(10, col.Column), Cells(82, col.Column))) =
0 Then
(watch out for the line wrapping)
For your second request autofiltering the data where A does not equal 0
would be the easiest way to do it but if you want a macro to hide the rows
use something like this:
Sub hide_rows()
Dim endRow As Long
Dim ColA As Range
Dim Cell As Range
Sheets("Report").Select
endRow = Cells(Rows.Count, 1).End(xlUp).Row
Set ColA = Range(Cells(2, 1), Cells(endRow, 1))
For Each Cell In ColA
If Cell.Value = 0 Then
Cell.EntireRow.Hidden = True
End If
Next Cell
End Sub
Hope this helps
Rowan
"Hawk" wrote:
Can anyone provide help with a time sensitive request?? Before I
begin, I have to say that I am an Accountant, not a programmer, so
please keep that in mind if/when you respond...
I have a workbook that contains two worksheets. One is a data entry
sheet that users will input employee data into and the other sheet is
the actual report that contains all formulas that pull info from the
data entry page. On the data entry page, the sheet begins with 30
columns that the user will input employee information into. One column
represents one employee. However, all 30 columns are not always
needed. I would like to create a macro (with a button) that will hide
the empty columns just for the purposes of printing the document so
that empty columns are not printed on the page. (Note: The empty
columns do contain formulas.)
I've searched for solutions on the web and I've come up with the
following, however, when I run the macro all 30 columns get hidden even
if there is data in them:
Sub Hide_EmptyColumns()
'To hide columns with no data in rows 10:82
Sheets("Box").Select
Dim col As Range
For Each col In Columns("C:AF")
If Application.Count(Range(Cells(4, col.Column), Cells(8, col.Column)))
= 0 Then
col.Hidden = True
End If
Next
End Sub
Also, all the data entered on the data entry page links to another
sheet, which is the report. However, the report contains employee
information in the rows, instead of columns. So, one row represents an
employee. I need a macro (with a button) that will hide the empty rows
for printing purposes so that blank rows will not appear on the report.
The only problem is that there is a formula in EVERY cell on the
report. So I need something that will look at column "A" and if the
formula result is "0" it will hide the entire row. I don't have a
possible solution for this one because I'm stuck on the first problem.
I really hope that I was clear. Anyone's help would be greatly
appreciated. I really need to have this done by tomorrow, if possible.
THANK YOU!!!
|