Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default multiple ranges in cell notation

How can you represent this in cell notation so you can use variables?

Set My_Multiple_Range = Range("a1:a3,a7:a9")

thanks
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default multiple ranges in cell notation

you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))

--


Gary


"John" wrote in message
...
How can you represent this in cell notation so you can use variables?

Set My_Multiple_Range = Range("a1:a3,a7:a9")

thanks
John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default multiple ranges in cell notation

How about this

Set My_Multiple_Range = Union(Range("a1:a3"),Range("a7:a9"))
--
HTH,
Barb Reinhardt



"John" wrote:

How can you represent this in cell notation so you can use variables?

Set My_Multiple_Range = Range("a1:a3,a7:a9")

thanks
John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default multiple ranges in cell notation

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default multiple ranges in cell notation

Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt



"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default multiple ranges in cell notation

But not quite that simple <vbg:


With ActiveSheet 'I like to qualify my ranges.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Range(.Cells(X + 2, Y + 2), .Cells(X + 7, Y)), _
.Cells(X + 7, Y + 7))
End With

or

With ActiveSheet 'I like to qualify my ranges, still.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Cells(X + 2, Y + 2).Offset(0, -2).Resize(6, 3), _
.Cells(X + 7, Y + 7))
End With


Barb Reinhardt wrote:

Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt

"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))



--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default multiple ranges in cell notation

It looks like that sets the individual cells rather than two ranges.
I'll give it a try tough.
thanks
John


Barb Reinhardt wrote:
Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default multiple ranges in cell notation

I had to take the periods out of this to get it through debug.

What I',looking for is to have a range that is the first 3 cells in a
row plus cells 6 through 10 in the same row. or put another way. I want
the range to include cells 1 to 10 in a row but not cells 4 through 6.
And I want the row to be variable.



John

Dave Peterson wrote:
But not quite that simple <vbg:


With ActiveSheet 'I like to qualify my ranges.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Range(.Cells(X + 2, Y + 2), .Cells(X + 7, Y)), _
.Cells(X + 7, Y + 7))
End With

or

With ActiveSheet 'I like to qualify my ranges, still.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Cells(X + 2, Y + 2).Offset(0, -2).Resize(6, 3), _
.Cells(X + 7, Y + 7))
End With


Barb Reinhardt wrote:
Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt

"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default multiple ranges in cell notation

If you removed the dots, then you also removed the with statement. You didn't
need to do that and shouldn't have done that. I can't think of a time when it's
better to use unqualified ranges.

And I'm confused with your explanation. First 3 cells plus 6-10, then not cells
4-6. What happens with column F????

Dim myRow as long
dim myRng as range
myrow = 12 'whatever

with activesheet 'here it is again!
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,6).resize(1,5))
msgbox myrng.address
'or
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,7).resize(1,4))
msgbox myrng.address
end with

John wrote:

I had to take the periods out of this to get it through debug.

What I',looking for is to have a range that is the first 3 cells in a
row plus cells 6 through 10 in the same row. or put another way. I want
the range to include cells 1 to 10 in a row but not cells 4 through 6.
And I want the row to be variable.

John

Dave Peterson wrote:
But not quite that simple <vbg:


With ActiveSheet 'I like to qualify my ranges.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Range(.Cells(X + 2, Y + 2), .Cells(X + 7, Y)), _
.Cells(X + 7, Y + 7))
End With

or

With ActiveSheet 'I like to qualify my ranges, still.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Cells(X + 2, Y + 2).Offset(0, -2).Resize(6, 3), _
.Cells(X + 7, Y + 7))
End With


Barb Reinhardt wrote:
Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt

"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))



--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default multiple ranges in cell notation

Some others:

with activesheet
set myrng = union(.rows(myrow).cells(1).range("A1:c1"), _
.rows(myrow).cells(1).range("F1:J1"))
end with

with activesheet
set myrng = intersect(.rows(myrow), .range("a:c,f:j").entirecolumn)
end with


Dave Peterson wrote:

If you removed the dots, then you also removed the with statement. You didn't
need to do that and shouldn't have done that. I can't think of a time when it's
better to use unqualified ranges.

And I'm confused with your explanation. First 3 cells plus 6-10, then not cells
4-6. What happens with column F????

Dim myRow as long
dim myRng as range
myrow = 12 'whatever

with activesheet 'here it is again!
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,6).resize(1,5))
msgbox myrng.address
'or
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,7).resize(1,4))
msgbox myrng.address
end with

John wrote:

I had to take the periods out of this to get it through debug.

What I',looking for is to have a range that is the first 3 cells in a
row plus cells 6 through 10 in the same row. or put another way. I want
the range to include cells 1 to 10 in a row but not cells 4 through 6.
And I want the row to be variable.

John

Dave Peterson wrote:
But not quite that simple <vbg:


With ActiveSheet 'I like to qualify my ranges.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Range(.Cells(X + 2, Y + 2), .Cells(X + 7, Y)), _
.Cells(X + 7, Y + 7))
End With

or

With ActiveSheet 'I like to qualify my ranges, still.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Cells(X + 2, Y + 2).Offset(0, -2).Resize(6, 3), _
.Cells(X + 7, Y + 7))
End With


Barb Reinhardt wrote:
Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt

"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))



--

Dave Peterson


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default multiple ranges in cell notation

Yes... I don't understand what the with statement is for. I'm obviously
not an experienced excel programmer. All of what I'm doing occurs with
one sheet.

This is what seems to work for me:

Set MyNew = Union(Range(Cells(Rw, 1), Cells(Rw, 3)), Range(Cells(Rw, 7),
Cells(Rw, 9)))

John

Dave Peterson wrote:
If you removed the dots, then you also removed the with statement. You didn't
need to do that and shouldn't have done that. I can't think of a time when it's
better to use unqualified ranges.

And I'm confused with your explanation. First 3 cells plus 6-10, then not cells
4-6. What happens with column F????

Dim myRow as long
dim myRng as range
myrow = 12 'whatever

with activesheet 'here it is again!
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,6).resize(1,5))
msgbox myrng.address
'or
set myrng = union(.cells(myrow,1).resize(1,3), _
.cells(myrow,7).resize(1,4))
msgbox myrng.address
end with

John wrote:
I had to take the periods out of this to get it through debug.

What I',looking for is to have a range that is the first 3 cells in a
row plus cells 6 through 10 in the same row. or put another way. I want
the range to include cells 1 to 10 in a row but not cells 4 through 6.
And I want the row to be variable.

John

Dave Peterson wrote:
But not quite that simple <vbg:


With ActiveSheet 'I like to qualify my ranges.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Range(.Cells(X + 2, Y + 2), .Cells(X + 7, Y)), _
.Cells(X + 7, Y + 7))
End With

or

With ActiveSheet 'I like to qualify my ranges, still.
Set My_Multiple_Range _
= Union(.Cells(X, Y), _
.Cells(X + 2, Y + 2).Offset(0, -2).Resize(6, 3), _
.Cells(X + 7, Y + 7))
End With


Barb Reinhardt wrote:
Then you want
Set My_multiple_Range =
Union(Cells(x,y),cells(x+2,y+2),Cells(x+7,y),cells (x+7,Y+7))

It's not that hard.
--
HTH,
Barb Reinhardt

"John" wrote:

I wasn't clear

I want something like

My_multiple_Range =
Range(Cells(x,y),cells(x+2,y+2):Cells(x+7,y),cells (x+7,Y+7)

So that I can use x and y as variables
John

Gary Keramidas wrote:
you can try this:

Set My_Multiple_Range = Union(Range("a1:a3"), Range("a7:a9"))


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
Extending Look-up to multiple cell ranges sony654 Excel Worksheet Functions 4 April 5th 08 04:44 AM
Locking multiple Cell Ranges with TimeStamp junoon Excel Programming 0 May 27th 06 04:23 AM
Selecting multiple ranges using 'Cells' notation Pete[_22_] Excel Programming 4 June 30th 05 05:42 PM
Refer to Ranges using Cells notation Scott P Excel Programming 3 June 30th 05 06:08 AM
Multiple Vectors Notation Bill Martin -- (Remove NOSPAM from address) Excel Discussion (Misc queries) 0 May 3rd 05 06:56 PM


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