PC Review


Reply
Thread Tools Rate Thread

Defining multiple ranges as one range

 
 
yeekiat
Guest
Posts: n/a
 
      25th May 2009
Hi,

I'm new here. cheers to anyone who can help me.

Is there a way for me to define multiple ranges as one range in vba?
The trick to this is that I am not sure how many of them are to be
grouped together as it is dyanamic and changes all the time.

For example. Lets say the ranges E7 to G7 are to be grouped together.
I wish to group all of them as one cell and give it a name such as
GroupedCells, so that I can run codes using Range
("GroupedCells").Value = blablabla.

I know some would suggest that I use Range("GroupedCells") = Range
("E7:G7") but that is not possible because sometimes it could be F7,
G7, H7, I7, etc. depending on whether that particular range is filled.

If it helps I do know how many ranges I'm expected to group. So if it
helps I know that for the case of E7 to G7, the number of cells is 3.

I'll be thankful if anyone can help me out.

Regards,
Yee Kiat
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      25th May 2009
Not quite sure of what you want but try this idea

range("a3, z3,c4,a4:b12")

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"yeekiat" <(E-Mail Removed)> wrote in message
news:a10b5820-02e7-40a8-b6f4-(E-Mail Removed)...
> Hi,
>
> I'm new here. cheers to anyone who can help me.
>
> Is there a way for me to define multiple ranges as one range in vba?
> The trick to this is that I am not sure how many of them are to be
> grouped together as it is dyanamic and changes all the time.
>
> For example. Lets say the ranges E7 to G7 are to be grouped together.
> I wish to group all of them as one cell and give it a name such as
> GroupedCells, so that I can run codes using Range
> ("GroupedCells").Value = blablabla.
>
> I know some would suggest that I use Range("GroupedCells") = Range
> ("E7:G7") but that is not possible because sometimes it could be F7,
> G7, H7, I7, etc. depending on whether that particular range is filled.
>
> If it helps I do know how many ranges I'm expected to group. So if it
> helps I know that for the case of E7 to G7, the number of cells is 3.
>
> I'll be thankful if anyone can help me out.
>
> Regards,
> Yee Kiat


 
Reply With Quote
 
yeekiat
Guest
Posts: n/a
 
      25th May 2009
Basically I need to group a bunch of cells together and give them a
name called GroupedCells.

Normally you would do this by doing:

Range("GroupedCells") = Range("A1:C1")

This is all well and good if you know the last cell that you want to
group together is C1. However I do now know that. As such I have to
write a code that will help me determine the end cell, possibly using
IsEmpty or whatever to find out the end cell. It helps that I know the
number of cells to be grouped together. So for the case of A1:C1, it
is 3. and for the case of A1:B1 it is 2. How do I make use of that
knowledge to find the end cell from A1 (they are all in the same row)
and how do I group them together as Range("GroupedCells")?

Thanks.


On May 25, 9:57*pm, "Don Guillett" <dguille...@austin.rr.com> wrote:
> Not quite sure of what you want but try this idea
>
> range("a3, z3,c4,a4:b12")
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> dguille...@austin.rr.com"yeekiat" <tanyk...@gmail.com> wrote in message
>
> news:a10b5820-02e7-40a8-b6f4-(E-Mail Removed)...
>
>
>
> > Hi,

>
> > I'm new here. cheers to anyone who can help me.

>
> > Is there a way for me to define multiple ranges as one range in vba?
> > The trick to this is that I am not sure how many of them are to be
> > grouped together as it is dyanamic and changes all the time.

>
> > For example. Lets say the ranges E7 to G7 are to be grouped together.
> > I wish to group all of them as one cell and give it a name such as
> > GroupedCells, so that I can run codes using Range
> > ("GroupedCells").Value = blablabla.

>
> > I know some would suggest that I use Range("GroupedCells") = Range
> > ("E7:G7") but that is not possible because sometimes it could be F7,
> > G7, H7, I7, etc. depending on whether that particular range is filled.

>
> > If it helps I do know how many ranges I'm expected to group. So if it
> > helps I know that for the case of E7 to G7, the number of cells is 3.

>
> > I'll be thankful if anyone can help me out.

>
> > Regards,
> > Yee Kiat- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
yeekiat
Guest
Posts: n/a
 
      25th May 2009
I have found the solution:

Set GroupedRange = Range("E7", Range("E7").End(xlToRight))

Thanks for the help


On May 25, 10:16*pm, yeekiat <tanyk...@gmail.com> wrote:
> Basically I need to group a bunch of cells together and give them a
> name called GroupedCells.
>
> Normally you would do this by doing:
>
> Range("GroupedCells") = Range("A1:C1")
>
> This is all well and good if you know the last cell that you want to
> group together is C1. However I do now know that. As such I have to
> write a code that will help me determine the end cell, possibly using
> IsEmpty or whatever to find out the end cell. It helps that I know the
> number of cells to be grouped together. So for the case of A1:C1, it
> is 3. and for the case of A1:B1 it is 2. How do I make use of that
> knowledge to find the end cell from A1 (they are all in the same row)
> and how do I group them together as Range("GroupedCells")?
>
> Thanks.
>
> On May 25, 9:57*pm, "Don Guillett" <dguille...@austin.rr.com> wrote:
>
>
>
> > Not quite sure of what you want but try this idea

>
> > range("a3, z3,c4,a4:b12")

>
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > dguille...@austin.rr.com"yeekiat" <tanyk...@gmail.com> wrote in message

>
> >news:a10b5820-02e7-40a8-b6f4-(E-Mail Removed)....

>
> > > Hi,

>
> > > I'm new here. cheers to anyone who can help me.

>
> > > Is there a way for me to define multiple ranges as one range in vba?
> > > The trick to this is that I am not sure how many of them are to be
> > > grouped together as it is dyanamic and changes all the time.

>
> > > For example. Lets say the ranges E7 to G7 are to be grouped together.
> > > I wish to group all of them as one cell and give it a name such as
> > > GroupedCells, so that I can run codes using Range
> > > ("GroupedCells").Value = blablabla.

>
> > > I know some would suggest that I use Range("GroupedCells") = Range
> > > ("E7:G7") but that is not possible because sometimes it could be F7,
> > > G7, H7, I7, etc. depending on whether that particular range is filled..

>
> > > If it helps I do know how many ranges I'm expected to group. So if it
> > > helps I know that for the case of E7 to G7, the number of cells is 3.

>
> > > I'll be thankful if anyone can help me out.

>
> > > Regards,
> > > Yee Kiat- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      25th May 2009
For that you could use a dynamic name, no code need to update to update

=OFFSET(Sheet1!$E$7,0,0,1,COUNTA(Sheet1!$E$7:$IV$7))

Ensure there are no empty cells in the range (other than those to the right
of the last used cell)

Change $IV$7 for Excel 2007, or better still reduce to the left to the last
cell you imagine might ever need to be included.

Regards,
Peter T


"yeekiat" <(E-Mail Removed)> wrote in message
news:21b3842e-e547-47da-ba1b-(E-Mail Removed)...
I have found the solution:

Set GroupedRange = Range("E7", Range("E7").End(xlToRight))

Thanks for the help


On May 25, 10:16 pm, yeekiat <tanyk...@gmail.com> wrote:
> Basically I need to group a bunch of cells together and give them a
> name called GroupedCells.
>
> Normally you would do this by doing:
>
> Range("GroupedCells") = Range("A1:C1")
>
> This is all well and good if you know the last cell that you want to
> group together is C1. However I do now know that. As such I have to
> write a code that will help me determine the end cell, possibly using
> IsEmpty or whatever to find out the end cell. It helps that I know the
> number of cells to be grouped together. So for the case of A1:C1, it
> is 3. and for the case of A1:B1 it is 2. How do I make use of that
> knowledge to find the end cell from A1 (they are all in the same row)
> and how do I group them together as Range("GroupedCells")?
>
> Thanks.
>
> On May 25, 9:57 pm, "Don Guillett" <dguille...@austin.rr.com> wrote:
>
>
>
> > Not quite sure of what you want but try this idea

>
> > range("a3, z3,c4,a4:b12")

>
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > dguille...@austin.rr.com"yeekiat" <tanyk...@gmail.com> wrote in message

>
> >news:a10b5820-02e7-40a8-b6f4-(E-Mail Removed)...

>
> > > Hi,

>
> > > I'm new here. cheers to anyone who can help me.

>
> > > Is there a way for me to define multiple ranges as one range in vba?
> > > The trick to this is that I am not sure how many of them are to be
> > > grouped together as it is dyanamic and changes all the time.

>
> > > For example. Lets say the ranges E7 to G7 are to be grouped together.
> > > I wish to group all of them as one cell and give it a name such as
> > > GroupedCells, so that I can run codes using Range
> > > ("GroupedCells").Value = blablabla.

>
> > > I know some would suggest that I use Range("GroupedCells") = Range
> > > ("E7:G7") but that is not possible because sometimes it could be F7,
> > > G7, H7, I7, etc. depending on whether that particular range is filled.

>
> > > If it helps I do know how many ranges I'm expected to group. So if it
> > > helps I know that for the case of E7 to G7, the number of cells is 3.

>
> > > I'll be thankful if anyone can help me out.

>
> > > Regards,
> > > Yee Kiat- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -



 
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
Defining Multiple "named" data ranges for Piot Tables in Excel 200 =?Utf-8?B?RmF0aWggQ2FuMTk2OA==?= Microsoft Excel Misc 1 23rd Mar 2007 03:29 PM
sum the values of a range based upon multiple ranges and criteria =?Utf-8?B?TGl2ZUl0Li4u?= Microsoft Excel Worksheet Functions 1 17th Jul 2006 09:23 PM
Range matching multiple named Ranges =?Utf-8?B?YmVuIHNpbXBzb24=?= Microsoft Excel Misc 0 15th Mar 2006 06:45 PM
Re-defining Ranges in VBA =?Utf-8?B?YWVoYW4=?= Microsoft Excel Programming 3 24th Mar 2005 05:15 PM
A range variable consisting of multiple ranges. cpeters5@yahoo.com Microsoft Excel Programming 7 4th Jan 2005 08:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.