Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default Selecting multiple ranges

I want to select multiple contiguous row ranges in non-contiguous columns but can't seem
to figure it out.

The macro recorder equivalent is
Range("U2:U12,Y2:Y12").Select

This is an abbreviation of what I want as I'm trying to select five ranges in all.

From the VBA "Help" it appears as if I'd have to use "Union", is there another way (or
I'll have a statement that will go on forever!)?

--
Regards;
Rob
------------------------------------------------------------------------


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Selecting multiple ranges

What is the problem you're having?

Range("U2:U12,Y2:Y12").Select

works as expected, and so does this, with five areas:

Range("A2:A12,D2:D12,L15:P25,U2:U12,Y2:Y12").Selec t

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"RWN" wrote in message
...
I want to select multiple contiguous row ranges in non-contiguous columns
but can't seem
to figure it out.

The macro recorder equivalent is
Range("U2:U12,Y2:Y12").Select

This is an abbreviation of what I want as I'm trying to select five ranges
in all.

From the VBA "Help" it appears as if I'd have to use "Union", is there
another way (or
I'll have a statement that will go on forever!)?

--
Regards;
Rob
------------------------------------------------------------------------




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting multiple ranges

set rng2 = Intersect(Range("U:U,Y:Y,AC:AC,AG:AG,AK:AK"),Range ("2:12"))
? rng2.Address(0,0)
U2:U12,Y2:Y12,AC2:AC12,AG2:AG12,AK2:AK12


Sub BBB()
Dim rng As Range, rng1 As Range
Set rng = Range("U2:U12")
Set rng1 = rng
For i = 1 To 4
Set rng = Union(rng, rng1.Offset(0, i * 4))
Next
Debug.Print rng.Address(0, 0)

End Sub

also produces
U2:U12,Y2:Y12,AC2:AC12,AG2:AG12,AK2:AK12

--
Regards,
Tom Ogilvy


"RWN" wrote in message
...
I want to select multiple contiguous row ranges in non-contiguous columns
but can't seem
to figure it out.

The macro recorder equivalent is
Range("U2:U12,Y2:Y12").Select

This is an abbreviation of what I want as I'm trying to select five ranges
in all.

From the VBA "Help" it appears as if I'd have to use "Union", is there
another way (or
I'll have a statement that will go on forever!)?

--
Regards;
Rob
------------------------------------------------------------------------




  #4   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default Selecting multiple ranges

Jon,. thanks.
I was using the recorder for an example only.
In real life my ranges will be variable and I could never figure out how to replicate the
recorder.

Typically I will select as;
Range(Cells(ro,co),Cells(r,c)).Select
Where the r,c values may be set by a CurrentRegion.rows|columns.count, for example.

Am I missing something?
(I admit to "getting in trouble" with the Range function)
--
Regards;
Rob
------------------------------------------------------------------------
"Jon Peltier" wrote in message
...
What is the problem you're having?

Range("U2:U12,Y2:Y12").Select

works as expected, and so does this, with five areas:

Range("A2:A12,D2:D12,L15:P25,U2:U12,Y2:Y12").Selec t

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"RWN" wrote in message
...
I want to select multiple contiguous row ranges in non-contiguous columns
but can't seem
to figure it out.

The macro recorder equivalent is
Range("U2:U12,Y2:Y12").Select

This is an abbreviation of what I want as I'm trying to select five ranges
in all.

From the VBA "Help" it appears as if I'd have to use "Union", is there
another way (or
I'll have a statement that will go on forever!)?

--
Regards;
Rob
------------------------------------------------------------------------






  #5   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default Selecting multiple ranges

Thanks Tom, your second example is what I was looking for.
My version is;
Sub TestI()
Dim rng As Range
Dim rng1 As Range
Set rng = Range(Cells(2, TargetCol), Cells(LastRow, TargetCol))
Set rng1 = rng
For i = 1 To 4
Set rng = Union(rng, rng1.Offset(0, i * 4))
Next
rng.Select
End Sub

My confusion with ranges revolves around the fact that I don't know how to programatically
create the range using an "A1" format.

Again, thanks
--
Regards;
Rob
------------------------------------------------------------------------
"Tom Ogilvy" wrote in message
...
set rng2 = Intersect(Range("U:U,Y:Y,AC:AC,AG:AG,AK:AK"),Range ("2:12"))
? rng2.Address(0,0)
U2:U12,Y2:Y12,AC2:AC12,AG2:AG12,AK2:AK12


Sub BBB()
Dim rng As Range, rng1 As Range
Set rng = Range("U2:U12")
Set rng1 = rng
For i = 1 To 4
Set rng = Union(rng, rng1.Offset(0, i * 4))
Next
Debug.Print rng.Address(0, 0)

End Sub

also produces
U2:U12,Y2:Y12,AC2:AC12,AG2:AG12,AK2:AK12

--
Regards,
Tom Ogilvy


"RWN" wrote in message
...
I want to select multiple contiguous row ranges in non-contiguous columns
but can't seem
to figure it out.

The macro recorder equivalent is
Range("U2:U12,Y2:Y12").Select

This is an abbreviation of what I want as I'm trying to select five ranges
in all.

From the VBA "Help" it appears as if I'd have to use "Union", is there
another way (or
I'll have a statement that will go on forever!)?

--
Regards;
Rob
------------------------------------------------------------------------






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
Trouble with selecting multiple ranges of data markag Excel Worksheet Functions 2 June 23rd 06 04:35 PM
Selecting multiple ranges [email protected] Excel Programming 5 February 2nd 06 06:49 PM
Selecting multiple ranges using 'Cells' notation Pete[_22_] Excel Programming 4 June 30th 05 05:42 PM
selecting multiple ranges Helen Excel Programming 3 January 16th 05 03:46 AM
Selecting ranges Steve Wood Excel Programming 1 August 24th 04 02:16 PM


All times are GMT +1. The time now is 12:04 AM.

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"