PC Review


Reply
Thread Tools Rate Thread

Converting range to variant is easy; how do I handle rows vs colum

 
 
ker_01
Guest
Posts: n/a
 
      30th Jul 2009
I've created some code for myself that works pretty well. I input two
(vertical) ranges of data via a UDF that are then processed and modify my
sheet as desired. Here is a simplified example of the piece of code I need to
tweak

Dim RangeToArray as Variant

RangeToArray = Sheet1.Range("A1:A4").value
'Actual range is entered via a UDF, so it could be anywhere- this is just an
example

for i = lbound(RangeToArray) to ubound(RangeToArray)
TempCellValue = RangeToArray(i,1)
'do stuff
Next

Now I need to share it with other users, and I want the code to handle
different range entries without blowing up.

Situation: User places data in a horizontal range instead of a vertical range

My Approach: Check ubound of the range. If =1, then either it is a
horizontal range, or there is only one data point. Loop the horizontal range
and pull the data values out into a format that is compatible with the rest
of my code.

Problem: In my testing, I haven't been able to figure out how to find the
max number of [horizontal] elements "i" in RangeToArray(1,i)
[note, i is now the second parameter for a horizontal array]

Ubound doesn't seem to work on this; I tried variations like
ubound(RangeToArray(2)). Should I just make an obscenely high fixed loop (i=
1 to 1000000) and just catch the out of bounds error when it occurs, or is
there a better way to find the width of a horizontal range that has been
passed to a variant?

Thank you!
Keith
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      30th Jul 2009
Ubound(RangeToArray)
OR
Ubound(RangeToArray,1) will return the upper bound of the first dimension


Ubound(RangeToArray,2) will return the upper bound of the second dimension

If this post helps click Yes
---------------
Jacob Skaria


"ker_01" wrote:

> I've created some code for myself that works pretty well. I input two
> (vertical) ranges of data via a UDF that are then processed and modify my
> sheet as desired. Here is a simplified example of the piece of code I need to
> tweak
>
> Dim RangeToArray as Variant
>
> RangeToArray = Sheet1.Range("A1:A4").value
> 'Actual range is entered via a UDF, so it could be anywhere- this is just an
> example
>
> for i = lbound(RangeToArray) to ubound(RangeToArray)
> TempCellValue = RangeToArray(i,1)
> 'do stuff
> Next
>
> Now I need to share it with other users, and I want the code to handle
> different range entries without blowing up.
>
> Situation: User places data in a horizontal range instead of a vertical range
>
> My Approach: Check ubound of the range. If =1, then either it is a
> horizontal range, or there is only one data point. Loop the horizontal range
> and pull the data values out into a format that is compatible with the rest
> of my code.
>
> Problem: In my testing, I haven't been able to figure out how to find the
> max number of [horizontal] elements "i" in RangeToArray(1,i)
> [note, i is now the second parameter for a horizontal array]
>
> Ubound doesn't seem to work on this; I tried variations like
> ubound(RangeToArray(2)). Should I just make an obscenely high fixed loop (i=
> 1 to 1000000) and just catch the out of bounds error when it occurs, or is
> there a better way to find the width of a horizontal range that has been
> passed to a variant?
>
> Thank you!
> Keith

 
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
The easy way to make the label of the field in the colum as a head Frank Situmorang Microsoft Access Reports 1 25th Dec 2007 05:15 PM
How to work with only one colum of a variant =?Utf-8?B?R3VubmFyIEFyb25zZW4=?= Microsoft Excel Programming 11 11th Apr 2007 12:54 AM
Can I program Colum B to record a range based on a values in colum =?Utf-8?B?Tmlrb2xl?= Microsoft Frontpage 1 17th Aug 2005 03:15 PM
Converting between VARIANT and std::string Torben Laursen Microsoft VC .NET 5 18th Aug 2004 12:01 PM
Option Box Colum Format (Easy Question) gwmurray Microsoft Access Forms 4 22nd Jan 2004 09:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 AM.