How do I assign comma separated values from an Inputbox to variables in VBA?
The code is to assign values in the array created by the inputbox into variables created based on the number of comma-separated values in the array. i.e. if 5 comma-separated values (1,2,3,4,5) are entered in the Inputbox the code create 5 variables input1, input2 etc. and assign values from the input.
I have tried the following code and it is returning a "subscript out of range" error at input(v) = u
Sub test3()
Dim strEntries As String, v As Long, item As Variant, inputArray() As String, u As Variant, input() As String
strEntries = Application.InputBox("Enter multiple comma separated values. ", "Entries", Type:=2)
If strEntries = "False" Then Exit Sub 'User canceled
v = 0
inputArray = Split(strEntries, ",")
For Each u In inputArray
Debug.Print u
For v = LBound(inputArray) To UBound(inputArray)
input(v) = u
Next v
v = v + 1
Debug.Print "count =" & v
Next u
End Sub
Comments
Post a Comment