Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Addcing a cell to a non-contigious range

I would like to add a cell to an existing range in a macro. I am new to
programming ranges and need some direction on this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Addcing a cell to a non-contigious range

Do you mean just make the range bigger?

If yes, you can use .resize() to resize the original range:

range("a1").resize(1,10)
refers to a range that is 1 row by 10 columns starting in A1.

Range("a1:B99").resize(1,10)
is the same as that other! 1 row by 10 columns starting in A1.

So if you wanted to resize an existing range, you could do:

dim myRng as Range
dim myNewRng as range
Set myrng = worksheets("sheet9999").range("c9:e44")

with myrng
set mynewrng = .resize(.rows.count+1,.columns.count+1)
end with

It added 1 to both the number of rows and the number of columns.

And you don't have to use a new variable if you don't want to:

with myrng
set myrng = .resize(.rows.count+1,.columns.count+1)
end with

=======
As an aside, there's a way to "move" to a different location based on that
original range. Take a look at .offset() in VBA's help when you have time.

Edd wrote:

I would like to add a cell to an existing range in a macro. I am new to
programming ranges and need some direction on this.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Addcing a cell to a non-contigious range

On May 27, 10:00 am, Edd wrote:
I would like to add a cell to an existing range in a macro. I am new to
programming ranges and need some direction on this.


Set MyRange = Union(MyRange, Range("C1"))

adds C1 to a previously Set range (MyRange)

Ken Johnson

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
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Change cell colour for a cell or range within a predefined range Martin[_21_] Excel Programming 2 May 23rd 05 06:16 PM
Comparing values in non contigious cells thePriest Excel Programming 3 March 3rd 05 05:21 AM
Multiply non-contigious arrays Rob Gould Excel Discussion (Misc queries) 7 February 28th 05 01:00 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM


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