Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Help me please understand this Visual Basic command

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,081
Default Help me please understand this Visual Basic command

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Co-op 20 Excel Discussion (Misc queries) 2 June 28th 07 09:06 PM
VISUAL BASIC COMMAND TO MOVE CURSER DOWN ONE CELL Moving Problem! Excel Worksheet Functions 2 December 19th 06 08:00 AM
changing the visual basic in office 2003 to visual studio net bigdaddy3 Excel Discussion (Misc queries) 1 September 13th 05 10:57 AM
Visual Basic Micos3 Excel Discussion (Misc queries) 9 June 28th 05 01:41 PM
Visual Basic Help Duncan Smith Excel Discussion (Misc queries) 1 December 3rd 04 09:13 AM


All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"