Printing

S

stevestr

Hello Brilliant Excel Users,

I have a macro that prints out sheets in my workbook but I want it to be
smarter about printing. For example, I have programmed my macro to filter
the data on one of my sheets and print two copies of that sheet. If the
filter turns up no rows of data, then there's no need to print that sheet.

How do I have program the macro to look at row 7 (the first row of data),
determine if it's blank and if it's blank, skip the printing command and
continue with the rest of the macro?

I know it's really simple but I can't figure out the If/Then programming.

Thanks,

Steve
 
O

OssieMac

Hi Steve,

Am I correct in assuming that by Filtering you mean AutoFilter. If so, the
following code example loops through the worksheets and counts the visible
cells in column 1 of the AutoFiltered range. If greater than 1 then data is
visible. If only 1 then only the column headers are visible.

Note that Rows cannot be counted in non contiguous visible rows. However,
Cells can be counted and hense to resize the filtered range to only one
column and count the cells instead of counting the rows.

Private Sub Test()

Dim ws As Worksheet
Dim rngFilter As Range

For Each ws In Worksheets
With ws
If .AutoFilterMode Then
With .AutoFilter.Range
'Assign first column only to rngFilter
Set rngFilter = _
.Resize(.Rows.Count, 1) _
.SpecialCells(xlCellTypeVisible)
End With

If rngFilter.Cells.Count > 1 Then
MsgBox rngFilter.Cells.Count - 1 _
& "rows of data on sht " & ws.Name
Else
MsgBox "Column headers only visible on " & _
ws.Name
End If
Else
MsgBox "No filters set on worksheet " _
& ws.Name
End If
End With
Next ws
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top