#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Printing

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Printing

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


--
Regards,

OssieMac


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Printing

Hi Steve

Try something along the lines of;

Sub PrintIf()
Dim rRow As Range

Set rRow = Sheet1.Rows(7)
'http://www.ozgrid.com/VBA/excel-vba-sheet-names.htm

If WorksheetFunction.CountBlank(rRow) = Sheet1.Columns.Count Then
Exit Sub
Else
'YOUR PRINT CODE
End If
End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"stevestr" wrote in message
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Printing

If Application.CountA(Rows(7)) 0 Then
'Your print code here
End If



"stevestr" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 printing problem--printing 1 document on 2 pages Bons Excel Discussion (Misc queries) 0 December 24th 09 04:15 PM
Excel Printing --Borders are not printing on the same page as data Stup88 Excel Discussion (Misc queries) 1 August 7th 07 09:34 AM
Printing a heading on each new page when printing Brian Excel Discussion (Misc queries) 3 November 15th 06 05:22 PM
Enable Double sided printing contiuously when printing multiple s. Lee Excel Discussion (Misc queries) 1 November 27th 04 01:58 AM
Printing? Worksheets not printing the same on multiple pc's! 43fan Excel Programming 2 April 29th 04 02:34 PM


All times are GMT +1. The time now is 07:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"