PC Review


Reply
Thread Tools Rate Thread

Addcing a cell to a non-contigious range

 
 
=?Utf-8?B?RWRk?=
Guest
Posts: n/a
 
      27th May 2007
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.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      27th May 2007
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
 
Reply With Quote
 
Ken Johnson
Guest
Posts: n/a
 
      27th May 2007
On May 27, 10:00 am, Edd <E...@discussions.microsoft.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation using ISBLANK with non-contigious cells Harry Flashman Microsoft Excel Discussion 2 6th Mar 2009 08:27 AM
Change cell colour for a cell or range within a predefined range =?Utf-8?B?TWFydGlu?= Microsoft Excel Programming 2 23rd May 2005 06:16 PM
Comparing values in non contigious cells thePriest Microsoft Excel Programming 3 3rd Mar 2005 05:21 AM
Multiply non-contigious arrays Rob Gould Microsoft Excel Misc 7 28th Feb 2005 01:00 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Microsoft Excel Programming 12 10th Jun 2004 04:22 AM


Features
 

Advertising
 

Newsgroups
 


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