Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
k k is offline
external usenet poster
 
Posts: 8
Default Convert string to range?

I have the following variables defined.

startxrange = Rng.Offset(2, 0).Address
startyrange = Rng.Offset(3, 0).Address
endxrange = Range(tempendxrange).Address
endyrange = Range(endxrange).Offset(1, 0).Address

Each of these has a value such as $A$2. I would like to combine the two
x-ranges together and the two y-ranges together and plug them into a later
part of my code that will use said ranges to perform calculations. Here is
what I tried to combine them together, using the x-range as an example.

Dim XRates As Range
XRates = startxrange & ":" & endxrange
MsgBox "XRates is " & XRates

Then my function performs this on the constructed range. Of course, this is
where my macro fails.

Count = XRates.Count

A newsgroup search I performed yielded one post that seemed to suggest using
Indirect, although I'm not sure how to work it into this example and if
that'd be recommended.

Any assistance as to what I'm doing wrong would be appreciated. Thanks in
advance.

k


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Convert string to range?

If I have understood you correctly, try this:

Dim XRates As Range
Dim CountCells As Long

Set XRates = Range(startxrange & ":" & endxrange)
MsgBox "XRates is " & XRates.Address

CountCells = XRates.Cells.Count

I'm not sure, if the last line is what
you're after, but Count is a built-in name,
so avoid using it as a variable name.
--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"k" skrev i en meddelelse
...
I have the following variables defined.

startxrange = Rng.Offset(2, 0).Address
startyrange = Rng.Offset(3, 0).Address
endxrange = Range(tempendxrange).Address
endyrange = Range(endxrange).Offset(1, 0).Address

Each of these has a value such as $A$2. I would like to combine the two
x-ranges together and the two y-ranges together and plug them into a later
part of my code that will use said ranges to perform calculations. Here is
what I tried to combine them together, using the x-range as an example.

Dim XRates As Range
XRates = startxrange & ":" & endxrange
MsgBox "XRates is " & XRates

Then my function performs this on the constructed range. Of course, this

is
where my macro fails.

Count = XRates.Count

A newsgroup search I performed yielded one post that seemed to suggest

using
Indirect, although I'm not sure how to work it into this example and if
that'd be recommended.

Any assistance as to what I'm doing wrong would be appreciated. Thanks in
advance.

k




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Convert string to range?

Ranges are objects, so you need to use the Set statement to assign a
variable to them:


Dim XRates As Range
Set XRates = Range(startxrange & ":" & endxrange)
MsgBox "XRates is " & XRates.Address

or

Dim XRates As Range
Set XRates = Range(Rng.Offset(2, 0), Range(tempendxrange))

In article ,
"k" wrote:

I have the following variables defined.

startxrange = Rng.Offset(2, 0).Address
startyrange = Rng.Offset(3, 0).Address
endxrange = Range(tempendxrange).Address
endyrange = Range(endxrange).Offset(1, 0).Address

Each of these has a value such as $A$2. I would like to combine the two
x-ranges together and the two y-ranges together and plug them into a later
part of my code that will use said ranges to perform calculations. Here is
what I tried to combine them together, using the x-range as an example.

Dim XRates As Range
XRates = startxrange & ":" & endxrange
MsgBox "XRates is " & XRates

Then my function performs this on the constructed range. Of course, this is
where my macro fails.

Count = XRates.Count

A newsgroup search I performed yielded one post that seemed to suggest using
Indirect, although I'm not sure how to work it into this example and if
that'd be recommended.

Any assistance as to what I'm doing wrong would be appreciated. Thanks in
advance.

k

  #4   Report Post  
Posted to microsoft.public.excel.programming
k k is offline
external usenet poster
 
Posts: 8
Default Convert string to range?

Thanks for both responses; they solved my problem. As you can tell, I'm not
much of a VBA programmer, but I'd be much farther behind if not for this
newsgroup. It's an amazing resource powered by helpful & knowledgeable
individuals. Thanks again.

k

"Leo Heuser" wrote in message
...
If I have understood you correctly, try this:

Dim XRates As Range
Dim CountCells As Long

Set XRates = Range(startxrange & ":" & endxrange)
MsgBox "XRates is " & XRates.Address

CountCells = XRates.Cells.Count

I'm not sure, if the last line is what
you're after, but Count is a built-in name,
so avoid using it as a variable name.
--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"k" skrev i en meddelelse
...
I have the following variables defined.

startxrange = Rng.Offset(2, 0).Address
startyrange = Rng.Offset(3, 0).Address
endxrange = Range(tempendxrange).Address
endyrange = Range(endxrange).Offset(1, 0).Address

Each of these has a value such as $A$2. I would like to combine the two
x-ranges together and the two y-ranges together and plug them into a

later
part of my code that will use said ranges to perform calculations. Here

is
what I tried to combine them together, using the x-range as an example.

Dim XRates As Range
XRates = startxrange & ":" & endxrange
MsgBox "XRates is " & XRates

Then my function performs this on the constructed range. Of course, this

is
where my macro fails.

Count = XRates.Count

A newsgroup search I performed yielded one post that seemed to suggest

using
Indirect, although I'm not sure how to work it into this example and if
that'd be recommended.

Any assistance as to what I'm doing wrong would be appreciated. Thanks

in
advance.

k






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Convert string to range?

You're welcome "k".
We're glad to be able to help :-)

LeoH

"k" skrev i en meddelelse
...
Thanks for both responses; they solved my problem. As you can tell, I'm

not
much of a VBA programmer, but I'd be much farther behind if not for this
newsgroup. It's an amazing resource powered by helpful & knowledgeable
individuals. Thanks again.

k



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
Convert to string help pokdbz Excel Discussion (Misc queries) 1 June 10th 08 04:59 PM
convert a string to range? JK Excel Worksheet Functions 4 June 20th 06 01:04 AM
Convert String of 512 numbers to a range Kevin G[_2_] Excel Programming 10 February 2nd 04 06:02 AM
Scenariao needing help with. convert range to string and back, Kevin G[_2_] Excel Programming 0 January 28th 04 03:23 PM
VBA - Convert my variable range array to single cell string Kevin G[_2_] Excel Programming 6 January 28th 04 07:20 AM


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