Print Macro Button

Emb21

Board Regular
Joined
Jul 8, 2004
Messages
152
Hello,

I received this Print Macro from a board member but its printing all the sheets in my spreadsheet I have sheet named "Admin" which is the only one I want to print out with these rules applied below:

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 and above A20.

the worksheet name is "Admin"

Thanks,
Eric




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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Sub myAdminPrnt()
'

Sheets("Admin").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$216"

With ActiveSheet.PageSetup
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.FitToPagesWide = 1
.FitToPagesTall = False
End With

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
 
Upvote 0
It works for me?

It prints A1:J216 as landscape on letter paper, one page wide for as many pages as it takes to hit J216.
 
Upvote 0
For A21 thru J100 it need to print only the data that is enter but not print the other rows but it still prints the data below J100.

Thanks for all ur help.

Eric
 
Upvote 0
That's not what you said you needed?

Modify this to work with your ranges:

Sub Print2sheetsRanges()
'Standard module code.
'Print more than one sheets ranges as one print sheet.
Application.DisplayAlerts = False
Set NewSheet = Worksheets.Add
NewSheet.Name = "myTemp"

'Get print Ranges 1.
Sheets("Sheet1").Select

'Change your sheet1 range to whatever you want to print.
Range("A1:A13").Select

Selection.Copy
Sheets("myTemp").Select
ActiveSheet.Paste
ActiveCell.Select
'Find next empty cell.
'If you need a blank row between print ranges,
'increase the "Offset" by as many rows needed!
'If your range's last row, column "A" is blank,
'change the "A64000" to a data column!
'You can change "64000" to the max number of rows expected.
Range("A64000").End(xlUp).Offset(1, 0).Select
'End "Get print range1."
'For more than two print ranges: Copy "Get print range1" to here.
'Then change the range!
'Get last print range "Sheet2."
Sheets("Sheet2").Select

'Change your sheet2 range to whatever you want to print.
Range("A1:A9").Select

Application.CutCopyMode = False
Selection.Copy
Sheets("myTemp").Select
ActiveSheet.Paste
Application.CutCopyMode = False
'Print combined active range.
ActiveSheet.PageSetup.PrintArea = CurrentRegion
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
'Cleanup.
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet2").Select
Range("A1").Select
Sheets("Sheet1").Select
Range("A1").Select
Application.DisplayAlerts = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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
Back
Top