ignore this question i have get answerIs any only single formula to split full name as first and middle and last name
TEST_MREXCEL.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
2 | Frederick Stanley Smith | Frederick | Stanley | Smith | ||||
3 | Frederick Stanley Albert Reginald Smith-Lewington | Frederick | Stanley | Albert | Reginald | Smith-Lewington | ||
4 | ||||||||
Sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B2:F3 | B2 | =TRIM(MID(SUBSTITUTE(TRIM($A2)," ",REPT(" ",100)),((COLUMNS($B:B)-1)*100)+1,100)) |
one more small helpJust because I had worked on it. But I may have interpreted the question wrongly?
TEST_MREXCEL.xlsm
A B C D E F 2 Frederick Stanley Smith Frederick Stanley Smith 3 Frederick Stanley Albert Reginald Smith-Lewington Frederick Stanley Albert Reginald Smith-Lewington 4 Sheet2
Cell Formulas Range Formula B2:F3 B2 =TRIM(MID(SUBSTITUTE(TRIM($A2)," ",REPT(" ",100)),((COLUMNS($B:B)-1)*100)+1,100))
Sub SplitNames()
'
' SplitNames Macro
'
'
ActiveSheet.Paste
ActiveCell.FormulaR1C1 = _
"=TRIM(MID(SUBSTITUTE(RC1,"" "",REPT("" "",LEN(RC1))),COLUMNS(C1:C[-1])*LEN(RC1)-(LEN(RC1)-1),LEN(RC1)))"
ActiveCell.Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:A4")
ActiveCell.Range("A1:A4").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:C4"), Type:= _
xlFillDefault
ActiveCell.Range("A1:C4").Select
ActiveCell.Offset(4, 0).Range("A1").Select
End Sub
Sub Macro2()
Dim Lr As Long, i As Long, j As Long
Lr = Range("A" & Rows.Count).End(xlUp).Row
Range("B1").FormulaR1C1 = _
"=TRIM(MID(SUBSTITUTE(TRIM(RC1),"" "",REPT("" "",100)),((COLUMNS(C2:C)-1)*100)+1,100))"
Range("B1").AutoFill Destination:=Range("B1:B" & Lr)
Range("B1:B" & Lr).AutoFill Destination:=Range("B1:H" & Lr)
Range("B1:H" & Lr).Value = Range("B1:H" & Lr).Value
End Sub
Sub Macro2()
Dim Lr As Long, i As Long, j As Long, arr As Variant
Lr = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To Lr
arr = Range("A" & i).Value
Range("B" & i).Resize(, Len(arr) - Len(Replace(arr, " ", "")) + 1).Value = Split(arr, " ")
Next i
End Sub
Thank you so much it's working has per my requestif you want macro try this:
VBA Code:Sub Macro2() Dim Lr As Long, i As Long, j As Long Lr = Range("A" & Rows.Count).End(xlUp).Row Range("B1").FormulaR1C1 = _ "=TRIM(MID(SUBSTITUTE(TRIM(RC1),"" "",REPT("" "",100)),((COLUMNS(C2:C)-1)*100)+1,100))" Range("B1").AutoFill Destination:=Range("B1:B" & Lr) Range("B1:B" & Lr).AutoFill Destination:=Range("B1:H" & Lr) Range("B1:H" & Lr).Value = Range("B1:H" & Lr).Value End Sub
But also you can do it with Text to column option at Data Tab with Space as Delimiter
This one also working perfectly Once again Thank you so muchOr try this simpler Macro:
VBA Code:Sub Macro2() Dim Lr As Long, i As Long, j As Long, arr As Variant Lr = Range("A" & Rows.Count).End(xlUp).Row For i = 2 To Lr arr = Range("A" & i).Value Range("B" & i).Resize(, Len(arr) - Len(Replace(arr, " ", "")) + 1).Value = Split(arr, " ") Next i End Sub
Or try this simpler Macro:
VBA Code:Sub Macro2() Dim Lr As Long, i As Long, j As Long, arr As Variant Lr = Range("A" & Rows.Count).End(xlUp).Row For i = 2 To Lr arr = Range("A" & i).Value Range("B" & i).Resize(, Len(arr) - Len(Replace(arr, " ", "")) + 1).Value = Split(arr, " ") Next i End Sub [/CODE [/QUOTE]
using the same logic/macro on a field containing address which is to be split based on commas instead of spaces, can we replace " " with ","? doesnt seem to work. sample text is given below:Or try this simpler Macro:
VBA Code:Sub Macro2() Dim Lr As Long, i As Long, j As Long, arr As Variant Lr = Range("A" & Rows.Count).End(xlUp).Row For i = 2 To Lr arr = Range("A" & i).Value Range("B" & i).Resize(, Len(arr) - Len(Replace(arr, " ", "")) + 1).Value = Split(arr, " ") Next i End Sub
4668 Stonecoal Road,Celina, ohio,45822 |