Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003 printing problem--printing 1 document on 2 pages | Excel Discussion (Misc queries) | |||
Excel Printing --Borders are not printing on the same page as data | Excel Discussion (Misc queries) | |||
Printing a heading on each new page when printing | Excel Discussion (Misc queries) | |||
Enable Double sided printing contiuously when printing multiple s. | Excel Discussion (Misc queries) | |||
Printing? Worksheets not printing the same on multiple pc's! | Excel Programming |