Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Parallel ranges

Hello,

I have a situation where the user makes a selection in column
"A" (rng1). I need to create parallel ranges of this selection in
other columns on the same sheet (rng2). The following line of code
works well for single area selections, but only sets the first area on
multiple area selections.

Set rng2 = Range(rng1.Address).Offset(, col - 1)

I can accomplish what I want by looping through each area in column A,
but this seems to be somewhat inefficient when there's a lot of
columns involved. There must be a better way (hopefully). Thank you
for your suggestions.

I'm using Excel 97

Regards,

Dave

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Parallel ranges

This

Set Rng2 = Rng1.Offset(, Col - 1)

worked fine for me:

Sub TryNow()
Dim Rng1 As Range
Dim Rng2 As Range
Dim Col As Integer

Col = 3

Set Rng1 = Range("A1:A3,B10:B12")
MsgBox Rng1.Address
Set Rng2 = Rng1.Offset(, Col - 1)
MsgBox Rng2.Address

End Sub


--
HTH,
Bernie
MS Excel MVP


"Dave Unger" wrote in message
oups.com...
Hello,

I have a situation where the user makes a selection in column
"A" (rng1). I need to create parallel ranges of this selection in
other columns on the same sheet (rng2). The following line of code
works well for single area selections, but only sets the first area on
multiple area selections.

Set rng2 = Range(rng1.Address).Offset(, col - 1)

I can accomplish what I want by looping through each area in column A,
but this seems to be somewhat inefficient when there's a lot of
columns involved. There must be a better way (hopefully). Thank you
for your suggestions.

I'm using Excel 97

Regards,

Dave



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Parallel ranges

Hi Bernie,

Thanks for your reply, but this is still a problem for me.

Running your macro:

Set Rng1 = Range("A1:A3,B10:B12")
MsgBox Rng1.Address returns "$A$1:$A$3,$B$10:$B$12"

and

Set Rng2 = Rng1.Offset(, Col - 1)
MsgBox Rng2.Address returns "$C$1:$C$3"

Do you suppose this is a limitation of Excel 97?

regards,

Dave


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Parallel ranges

Do you suppose this is a limitation of Excel 97?

Yes it is. You'd have to approach it like this:

Sub a()
Dim Rng1 As Range, Rng2 As Range
Dim Area As Range
Set Rng1 = Range("A1:A3,B10:B12")
MsgBox Rng1.Address

For Each Area In Rng1.Areas
If Rng2 Is Nothing Then
Set Rng2 = Area
Else
Set Rng2 = Union(Area, Area.Offset(, 5))
End If
Next
MsgBox Rng2.Address
End Sub


--
Jim
"Dave Unger" wrote in message
oups.com...
| Hi Bernie,
|
| Thanks for your reply, but this is still a problem for me.
|
| Running your macro:
|
| Set Rng1 = Range("A1:A3,B10:B12")
| MsgBox Rng1.Address returns "$A$1:$A$3,$B$10:$B$12"
|
| and
|
| Set Rng2 = Rng1.Offset(, Col - 1)
| MsgBox Rng2.Address returns "$C$1:$C$3"
|
| Do you suppose this is a limitation of Excel 97?
|
| regards,
|
| Dave
|
|


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Parallel ranges

Hi Jim,

Thanks for your reply - I suspected this was route I'd have to go -
one of these days I'll update to a later version.

regards,

Dave

On Mar 26, 2:36 pm, "Jim Rech" wrote:
Do you suppose this is a limitation of Excel 97?


Yes it is. You'd have to approach it like this:

Sub a()
Dim Rng1 As Range, Rng2 As Range
Dim Area As Range
Set Rng1 = Range("A1:A3,B10:B12")
MsgBox Rng1.Address

For Each Area In Rng1.Areas
If Rng2 Is Nothing Then
Set Rng2 = Area
Else
Set Rng2 = Union(Area, Area.Offset(, 5))
End If
Next
MsgBox Rng2.Address
End Sub

--
Jim"Dave Unger" wrote in message

oups.com...
| Hi Bernie,
|
| Thanks for your reply, but this is still a problem for me.
|
| Running your macro:
|
| Set Rng1 = Range("A1:A3,B10:B12")
| MsgBox Rng1.Address returns "$A$1:$A$3,$B$10:$B$12"
|
| and
|
| Set Rng2 = Rng1.Offset(, Col - 1)
| MsgBox Rng2.Address returns "$C$1:$C$3"
|
| Do you suppose this is a limitation of Excel 97?
|
| regards,
|
| Dave
|
|



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
Parallel Box Plots Kristina Excel Discussion (Misc queries) 1 May 28th 10 07:18 PM
Parallel data series Martin[_2_] Excel Discussion (Misc queries) 1 May 28th 07 07:19 PM
To Draw A Line Parallel To A Curve At Particular Offset vijay4u Charts and Charting in Excel 1 August 9th 06 04:13 AM
Looping across two parallel ranges colin_e Excel Programming 4 March 1st 06 11:21 PM
Parallel Task (Threads) in VBa, is it possible? NooK[_35_] Excel Programming 3 July 7th 04 01:20 PM


All times are GMT +1. The time now is 09:40 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"