INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Remember Me

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Just copy and paste the

# Convert Variant To Array of Doubles?

Share

## Convert Variant To Array of Doubles?

(OP)
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

### RE: Convert Variant To Array of Doubles?

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

--------------------------------------------------------------------------------------------
Excel VBA Training and more Help at VBAExpress

### RE: Convert Variant To Array of Doubles?

(OP)
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

### RE: Convert Variant To Array of Doubles?

I'm not sure what operations you can't perform but, when that's the case, you can use, say, Cdbl(myvariant(3,1)) instead of just myvariant(3,1). 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

--------------------------------------------------------------------------------------------
Excel VBA Training and more Help at VBAExpress

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!