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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,047
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,118,020
Messages
5,569,664
Members
412,286
Latest member
kychemist00
Top