Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default A range variable consisting of multiple ranges.

Is it possible to do the following

- There are two names in a sheet:
test1 = "A1:A3" and test2 = "D12:D16"

- I would like to define a single range variable:
Dim testing As Range
Set testing = Union
(ThisWorkbook.Names"test1").RefersToRange,
ThisWorkbook.Names("test2").RefersToRange)

I know that this does not work, but is there a way to fix it ?
Thanks,
pac

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default A range variable consisting of multiple ranges.

Dim testing As Range
Set testing = Union(Range("Test1"),Range("Test2"))
Testing.Select

Test1 and test2 must be on the same sheet.

(although Your original should work as well. )

--
Regards,
Tom Ogilvy





wrote in message
oups.com...
Is it possible to do the following

- There are two names in a sheet:
test1 = "A1:A3" and test2 = "D12:D16"

- I would like to define a single range variable:
Dim testing As Range
Set testing = Union
(ThisWorkbook.Names"test1").RefersToRange,
ThisWorkbook.Names("test2").RefersToRange)

I know that this does not work, but is there a way to fix it ?
Thanks,
pac



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default A range variable consisting of multiple ranges.

pac,

If you used named ranges:

Dim testing As Range
Set testing = Union(Range("test1"), Range("test2"))
MsgBox testing.Address

HTH,
Bernie
MS Excel MVP

wrote in message
oups.com...
Is it possible to do the following

- There are two names in a sheet:
test1 = "A1:A3" and test2 = "D12:D16"

- I would like to define a single range variable:
Dim testing As Range
Set testing = Union
(ThisWorkbook.Names"test1").RefersToRange,
ThisWorkbook.Names("test2").RefersToRange)

I know that this does not work, but is there a way to fix it ?
Thanks,
pac



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default A range variable consisting of multiple ranges.

Thanks both Bernie and Tom for the answer. It gave me a jump start for
the day. made a lot of progress.

However, I was trying to ad a little bit of bells and whistles to the
code but was stuck with relative position from the range.


More explicitly, if given

Test1 = union(range("A1:a10"),range("Q5:Q23"))

How do I refer to the cell P5 using relative position to Test1?
Thanks,
pac

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default A range variable consisting of multiple ranges.

You could also use:

set test1 = range("a1:a10,q5:q23")
(if you were working with addresses.)

I'd use something like:

Dim test1 As Range
Dim test2 As Range
Set test1 = Range("a1:a10,q5:q23")
Set test2 = test1.Cells(1, 1).Offset(4, 15)
MsgBox test2.Address



" wrote:

Thanks both Bernie and Tom for the answer. It gave me a jump start for
the day. made a lot of progress.

However, I was trying to ad a little bit of bells and whistles to the
code but was stuck with relative position from the range.

More explicitly, if given

Test1 = union(range("A1:a10"),range("Q5:Q23"))

How do I refer to the cell P5 using relative position to Test1?
Thanks,
pac


--

Dave Peterson


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
Range matching multiple named Ranges ben simpson Excel Discussion (Misc queries) 0 March 15th 06 06:45 PM
Countif & ranges consisting of multiple areas Jurry Excel Worksheet Functions 2 November 15th 04 03:24 PM
Countif & ranges consisting of multiple areas Jurry Excel Worksheet Functions 0 November 15th 04 12:39 PM
Countif & ranges consisting of multiple areas Jurry Excel Worksheet Functions 1 November 15th 04 12:25 PM
Countif & ranges consisting of multiple areas Jurry Excel Worksheet Functions 1 November 15th 04 09:03 AM


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

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"