Convert variant array to string array

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
114
Office Version
  1. 365
Platform
  1. Windows
I have an array of 5 variant objects (text from userform textboxes) that I need to convert to string objects so that I can subsequently use the Left function with them. I found a thread posted by Mark O'Brien in 2002 about this (Convert Variant Array to String Array) but cannot get it to work.

Can anyone help convert my array to string objects please?

VBA Code:
Sub ArraytoString()

Dim Targets(1 To 5) As Variant
Dim MyTArray(1 To 5) As String
Dim i As Integer

Set Targets(1) = frmRapid1.txtNum1
Set Targets(2) = frmRapid1.txtNum2
Set Targets(3) = frmRapid1.txtNum3
Set Targets(4) = frmRapid1.txtNum4
Set Targets(5) = frmRapid1.txtNum5

ReDim MyTArray(UBound(Targets)) As String   'throws error array already dimensioned

For i = 1 To UBound(Targets)
MyTArray(i) = CStr(Targets(i))
Next

End Sub

Any help much appreciated.
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,387
Office Version
  1. 365
Platform
  1. Windows
It says it already dimensioned because you did that with the Dim statement when you put the 1 to 5 in it. Thats dimensioning the array.
 

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
114
Office Version
  1. 365
Platform
  1. Windows
It says it already dimensioned because you did that with the Dim statement when you put the 1 to 5 in it. Thats dimensioning the array.
Thanks steve the fish not familiar with re-dimensioning arrays. Got it working now, much appreciated.
 

Watch MrExcel Video

Forum statistics

Threads
1,128,176
Messages
5,629,176
Members
416,370
Latest member
Lgathana

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