S
Steve
I saw this in another thread and need someone to please explain with an
example how to use this code:
Print selection or range with one or more areas with a macro.
The macro will add a new sheet and copy all the selection areas on it.
Then it will print and delete the sheet.
Sub Test()
Dim Destrange As Range
Dim Smallrng As Range
Dim Newsh As Worksheet
Dim Ash As Worksheet
Dim Lr As Long
Application.ScreenUpdating = False
Set Ash = ActiveSheet
Set Newsh = Worksheets.Add
Ash.Select
Lr = 1
'You can also use a range with more areas like this
'For Each smallrng In Ash.Range("A1:C1,D10:G20,A30").Areas
For Each Smallrng In Selection.Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count
Next Smallrng
Newsh.Columns.AutoFit
Newsh.PrintOut
Application.DisplayAlerts = False
Newsh.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I understand how to name ranges but not sure from above what I am supposed
to name what. I have three ranges that I want to print.
Thanks!!!
example how to use this code:
Print selection or range with one or more areas with a macro.
The macro will add a new sheet and copy all the selection areas on it.
Then it will print and delete the sheet.
Sub Test()
Dim Destrange As Range
Dim Smallrng As Range
Dim Newsh As Worksheet
Dim Ash As Worksheet
Dim Lr As Long
Application.ScreenUpdating = False
Set Ash = ActiveSheet
Set Newsh = Worksheets.Add
Ash.Select
Lr = 1
'You can also use a range with more areas like this
'For Each smallrng In Ash.Range("A1:C1,D10:G20,A30").Areas
For Each Smallrng In Selection.Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count
Next Smallrng
Newsh.Columns.AutoFit
Newsh.PrintOut
Application.DisplayAlerts = False
Newsh.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I understand how to name ranges but not sure from above what I am supposed
to name what. I have three ranges that I want to print.
Thanks!!!