Prev: Control Z-Order of drop lines in an Excel 2007 chart?
Next: what is the code to close a file for a macro
From: stevestr on 1 Apr 2010 20:34 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
From: OssieMac on 1 Apr 2010 22:02 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
From: ozgrid.com on 1 Apr 2010 22:03 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" <stevestr(a)discussions.microsoft.com> wrote in message news:768BBD33-2B24-4F06-9FFA-F6DF6F211E36(a)microsoft.com... > 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
From: JLGWhiz on 1 Apr 2010 22:11
If Application.CountA(Rows(7)) > 0 Then 'Your print code here End If "stevestr" <stevestr(a)discussions.microsoft.com> wrote in message news:768BBD33-2B24-4F06-9FFA-F6DF6F211E36(a)microsoft.com... > 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 |