Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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!!! |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
this code doesn't look for named ranges, it is using the selected areas,
though the comment points out you could use specific addresses representing 3 different ranges: A1:C1,D10:G20,A30 So...to make this code work, simply select the areas you want copied and THEN run the macro "Steve" wrote: 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!!! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Visual Basic | Excel Discussion (Misc queries) | |||
VISUAL BASIC COMMAND TO MOVE CURSER DOWN ONE CELL | Excel Worksheet Functions | |||
changing the visual basic in office 2003 to visual studio net | Excel Discussion (Misc queries) | |||
Visual Basic | Excel Discussion (Misc queries) | |||
Visual Basic Help | Excel Discussion (Misc queries) |