HI
as I understand
please check the attachment
by the way it is not a macro but a UDF
hope it meets your requirement
There are various ways to do so.
I have arranged some of them. you may use the same fn in vba too.
Hi Deepak
Not giving expected results , could you look in
Thanks
Check this.
Just change the range.
Code:Sub split() Range("A2:A9").TextToColumns Destination:=Range("D2"), DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(8, 1)) End Sub
Sub Split()
Dim Arr, I As Long, Str As String
Arr = Range("A2", Cells(Rows.Count, 1).End(xlUp)).Value
For I = LBound(Arr) To UBound(Arr)
Cells(I + 1, 2) = VBA.Split(Arr(I, 1), " ")(0)
Cells(I + 1, 3) = Replace(Arr(I, 1), VBA.Split(Arr(I, 1), " ")(0), "")
Next I
End Sub
Try this
Code:Sub Split() Dim Arr, I As Long, Str As String Arr = Range("A2", Cells(Rows.Count, 1).End(xlUp)).Value For I = LBound(Arr) To UBound(Arr) Cells(I + 1, 2) = VBA.Split(Arr(I, 1), " ")(0) Cells(I + 1, 3) = Replace(Arr(I, 1), VBA.Split(Arr(I, 1), " ")(0), "") Next I End Sub
Sub test()
Dim r As Range
For Each r In Range("a2", Range("a" & Rows.Count).End(xlUp))
If r.Value Like "* *" Then
r(, 2).Resize(, 2).Value = Split(r.Value, " ", 2)
End If
Next
End Sub
RAM72
You will have problem when 2nd set of characters contains the 1st set of characters with REPLACE function.
If you like to use Split function, it should be
Code:Sub test() Dim r As Range For Each r In Range("a2", Range("a" & Rows.Count).End(xlUp)) If r.Value Like "* *" Then r(, 2).Resize(, 2).Value = Split(r.Value, " ", 2) End If Next End Sub
Sub yaser()
Dim Arr, I As Long, Str As String
Arr = Range("A2", Cells(Rows.Count, 1).End(xlUp)).Value
For I = LBound(Arr) To UBound(Arr)
Cells(I + 1, 2) = Trim(VBA.Split(Arr(I, 1), " ")(0))
Cells(I + 1, 3) = Trim(Replace(Arr(I, 1), VBA.Split(Arr(I, 1), " ")(0), ""))
Next I
End Sub