Convert Variant/String array to Variant/Double array

ttt123

Board Regular
Joined
May 31, 2006
Messages
120
Office Version
  1. 365
Platform
  1. Windows
Is there an easy way to change the data type of an array without looping over it? For example suppose I read in a csv file with a bunch of numerical values and then turn that into an Array via Split(), now I have an array of Variant/String; but suppose I wanted an array of Variant/Double, how would I do that efficiently(without looping)?

so in my example below, I'd like to get arr2 from strTest without looping.

Sub test()

Dim arr1 As Variant, arr2 As Variant, strTest As String, i As Long
strTest = "1,2,3"
arr1 = Split(strTest, ",")

ReDim arr2(LBound(arr1) To UBound(arr1))
For i = LBound(arr1) To UBound(arr1)
arr2(i) = CDbl(arr1(i))
Next i

End Sub

thanks in advance.
Taylour
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
:warning: Untested :warning:

Code:
ReDim Preserve arr2(LBound(arr1) To UBound(arr1)) As Double
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

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