Print Macro Button

Emb21

Board Regular
Joined
Jul 8, 2004
Messages
152
Hello,

What would be the macro to print a sheet for cells A1 thru J216?

but only print data thru cells A21 thru J129 and if there is no data in those cells then it wouldnt print those rows

but it still needs to print cells below it J130 thru J216.

the worksheet name is "Admin"

Thanks, :biggrin:
Eric
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

vconfused

Well-known Member
Joined
Jun 11, 2004
Messages
547
Something like this?

Code:
Sub Macro1()
Dim strOrigPrintArea As String
Dim shtSource As Worksheet, shtTemp As Worksheet
Dim iRow As Integer, iTotal As Integer

    Application.ScreenUpdating = False
    Set shtSource = Sheets("Admin")
    strOrigPrintArea = shtSource.PageSetup.PrintArea
    shtSource.PageSetup.PrintArea = ""
    Set shtTemp = Worksheets.Add
    shtSource.Range("A1:J216").Copy
    ActiveSheet.Paste
    
    iRow = 1
    iTotal = 129
    Do While iRow <= iTotal And iRow >= 1
        If Range("J" & iRow) = "" And Range("J" & iRow).End(xlToLeft).Column = 1 And Range("A" & iRow) = "" Then
            Rows(iRow).Delete
            iTotal = iTotal - 1
        Else
            iRow = iRow + 1
        End If
    Loop
    ActiveSheet.PageSetup.PrintArea = "$A$1:$J$" & iTotal + 216 - 130 + 1
    ActiveWorkbook.PrintOut
    Application.DisplayAlerts = False
    shtTemp.Delete
    Application.DisplayAlerts = True
    
    shtSource.PageSetup.PrintArea = strOrigPrintArea
    Application.ScreenUpdating = True
    
    
End Sub
 

Forum statistics

Threads
1,147,680
Messages
5,742,590
Members
423,740
Latest member
JCF_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top