Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Variant To Array of Doubles? 1

Status
Not open for further replies.

Jdoggers

Technical User
Feb 20, 2005
43
US
Hi,
I used a variant to copy a whole range of cells and store them. I was wondering if there was any way to redimension or convert it into an array of doubles. Example:

dim myvariant as variant
dim convertedarray() as double

myvariant = range("A1:D10").value

'this is where i would like to convert it into an array of doubles

'something like
convertedarray = cdbl(myvariant)

'or maybe
convertedarray = split(myvariant)

'or perhaps

x = 0

for each myelement in myvariant
convertedarray(x) = cdbl(myelement)

next

i have used similar approaches to these but none work. Any ideas or maybe something similar as something that i already tried to do?

thanks
 
Hi Jdoggers,

You can't change the (primary) datatype of a variable so your myvariant will always be a variant. You can if you want redimension an array of doubles to be the same size as the array in myvariant and then move each element separately. Do note, however, that ranges (and thus your variant) are two-dimensional. Is there a particular reason for wanting to do this?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
hey,
well there are some reasons. First, im trying to get around the fact that it takes lots of time to access each cell one cell at a time. That is why i copied the range to a variant. The reason that i want to convert them to doubles is so that i can perform operations on them like a normal array, since you cant perform operations on a variant in that manner. Thanks
 

I'm not sure what operations you can't perform but, when that's the case, you can use, say, [blue]Cdbl(myvariant(3,1))[/blue] instead of just [purple]myvariant(3,1)[/purple]. My guess is that would be quicker than moving all the individual elements one by one but it might depend on exactly what you were doing

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top