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
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,263
Messages
5,595,166
Members
413,973
Latest member
leon1974mk

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
Top