the position of the character

Try the next code, please:

Sub SplitString()
  Dim x As String, arr
  x = "11 23 77.6 556 7 696.5 33 22.1 34 23"
  arr = Split(x, " ")
  Range("A1").Resize(1, UBound(arr) + 1).Value = arr
End Sub

It will place each element in the range A1:J1. In fact, according do the array number of elements…

Edited to place a version returning doubles:

Sub SplitStringReturnDoubles()
  Dim x As String, arr, a() As Double, i As Long
  x = "11 23 77.6 556 7 696.5 33 22.1 34 23"
  arr = Split(x, " ")
  ReDim a(UBound(arr))
  For i = 0 To UBound(arr): a(i) = CDbl(arr(i)): Next i
  With Range("A1").Resize(1, UBound(arr) + 1)
    .Value = a
    .NumberFormat = "#.00"
  End With
End Sub

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top