Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Havig a problem Syntaxing a range ?

I am using this code from the user group to print separate areas of a
spreadsheet to one page.........
For Each Smallrng In Ash.Range("H1:T5, B3:E5").Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count + 1
Next Smallrng

The above works but I need to replace the ranges H1:T5 and B3:E5 with
variables to allow for changing ranges.
I have tried the obvious method of (for example) Range1 = "H1:T5" and
replaced the section of code with the variable but it fails to work. I
can't seam to get the right syntax to make it work.
Please embarrass me by pointing out the obvious solution.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Havig a problem Syntaxing a range ?

hi
try this
instead of .....Range1 = "H1:T5"
use this.........range1 = Range("H1:T5")

regards
FSt1

"Snowfire" wrote:

I am using this code from the user group to print separate areas of a
spreadsheet to one page.........
For Each Smallrng In Ash.Range("H1:T5, B3:E5").Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count + 1
Next Smallrng

The above works but I need to replace the ranges H1:T5 and B3:E5 with
variables to allow for changing ranges.
I have tried the obvious method of (for example) Range1 = "H1:T5" and
replaced the section of code with the variable but it fails to work. I
can't seam to get the right syntax to make it work.
Please embarrass me by pointing out the obvious solution.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Havig a problem Syntaxing a range ?

Snowfire wrote:
I am using this code from the user group to print separate areas of a
spreadsheet to one page.........
For Each Smallrng In Ash.Range("H1:T5, B3:E5").Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count + 1
Next Smallrng

The above works but I need to replace the ranges H1:T5 and B3:E5 with
variables to allow for changing ranges.
I have tried the obvious method of (for example) Range1 = "H1:T5" and
replaced the section of code with the variable but it fails to work. I
can't seam to get the right syntax to make it work.
Please embarrass me by pointing out the obvious solution.


Set Range1 = Range("H1:T5")

Alan Beban
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Havig a problem Syntaxing a range ?

Thanks for the suggestions but both fail or give an error message.....
This is the full macro...

Sub Test()
' Dim Destrange As Range, LastRowData As Range, LastRowTotals 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

' LastRowData = Range("H1:T9") '&
ActiveSheet.Cells(Cells.Rows.Count, 8).End(xlUp).Row)
' LastRowTotals = Range("B3:E5") ' &
ActiveSheet.Cells(Cells.Rows.Count, 2).End(xlUp).Row)
Set LastRowData = Range("H1:T9") '&
ActiveSheet.Cells(Cells.Rows.Count, 8).End(xlUp).Row)
setLastRowTotals = Range("B3:E5") ' &
ActiveSheet.Cells(Cells.Rows.Count, 2).End(xlUp).Row)

For Each Smallrng In Ash.Range(LastRowTotals, LastRowData).Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count + 1
Next Smallrng


With Newsh.PageSetup
.Orientation = xlLandscape
End With
Newsh.Columns.AutoFit

Newsh.PrintPreview 'PrintOut

Application.DisplayAlerts = False
Newsh.Delete
Application.DisplayAlerts = True

Application.ScreenUpdating = True

End Sub

I know the start of the ranges I need to capture, just need to find
the last row each time which works but can't get it to work in the for/
each statement?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Havig a problem Syntaxing a range ?

See below (and smack your forehead). This is an example of why
programmers advise that you always use Option Explicit.

Alan Beban

Snowfire wrote:
Thanks for the suggestions but both fail or give an error message.....
This is the full macro...

Sub Test()
' Dim Destrange As Range, LastRowData As Range, LastRowTotals 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

' LastRowData = Range("H1:T9") '&
ActiveSheet.Cells(Cells.Rows.Count, 8).End(xlUp).Row)
' LastRowTotals = Range("B3:E5") ' &
ActiveSheet.Cells(Cells.Rows.Count, 2).End(xlUp).Row)
Set LastRowData = Range("H1:T9") '&
ActiveSheet.Cells(Cells.Rows.Count, 8).End(xlUp).Row)
setLastRowTotals = Range("B3:E5") ' & <---------------Change to Set LastRowTotals
ActiveSheet.Cells(Cells.Rows.Count, 2).End(xlUp).Row)

For Each Smallrng In Ash.Range(LastRowTotals, LastRowData).Areas
Smallrng.Copy
Set Destrange = Newsh.Cells(Lr, 1)
Destrange.PasteSpecial xlPasteValues
Destrange.PasteSpecial xlPasteFormats
Lr = Lr + Smallrng.Rows.Count + 1
Next Smallrng


With Newsh.PageSetup
.Orientation = xlLandscape
End With
Newsh.Columns.AutoFit

Newsh.PrintPreview 'PrintOut

Application.DisplayAlerts = False
Newsh.Delete
Application.DisplayAlerts = True

Application.ScreenUpdating = True

End Sub

I know the start of the ranges I need to capture, just need to find
the last row each time which works but can't get it to work in the for/
each statement?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Havig a problem Syntaxing a range ?

Thanks Alan.... "couldn't see the wood for the trees"


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
3D range problem br549 Excel Worksheet Functions 1 June 15th 07 08:52 PM
Problem with range [email protected] Excel Discussion (Misc queries) 7 February 14th 07 04:06 PM
A problem with Set (Range) Peter Excel Programming 1 November 15th 05 09:31 PM
Range problem Ali Baba Excel Programming 2 September 15th 05 10:54 PM
Havig the replies sent to our address Dan E[_2_] Excel Programming 0 July 30th 03 03:47 PM


All times are GMT +1. The time now is 09:55 PM.

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

About Us

"It's about Microsoft Excel"