Copying a Range to an Array

orekin

Board Regular
Joined
Jun 1, 2004
Messages
50
Hi There

I have had my head in C# for a couple of years and my Excel VBA is a bit rusty! Here are my questions:

(1) I want to copy a range to an array of doubles, do some work, then copy the array back into the range ... but the only way I can seem to get it working is if I use a variant to store my data:

Dim myArray as Variant

'Range to Array
myArray = myRange.Value
' ** Do Work **
'Array to Range
myRange.Resize(UBound(myArray, 1), UBound(myArray, 2)).Value = myArray

Is there any way to copy a range to an array of doubles ? I am working with numbers so it is always doubles in the range

(2) How do I bulk copy an array of variants to an array of doubles ? (Without having to iterate through every element in the variant array and convert them to a doubles)

(3) In C# if statements, I can write:

if (condition1 && condition2)
{
//Do work here
}

And I know that the conditions are always evaluated left to right. Also, I know that if condition1 evaluates false, then condition two will not be evaluated.

Does the same thing occur in Excel VBA ?

Thanks
Orekin
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
1 Why do you need the array as double? If it's for calculation then you could use CDbl on the individual elements.

2 You can't.

3 Not as far as I know.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top