How to separate words from a string

Published: 15 April 2020
on channel: Learn Excel VBA Macros
34
3

Separate Words (First Name and Last Name ) from a string

You can use below VBA Macro for this task.

Sub SeparateStrings()
Dim ws As Worksheet
Dim StrName As String
Dim i As Integer
Dim Lrow As Long
Dim intComma As Integer

Set ws = ThisWorkbook.ActiveSheet

Lrow = ws.Range("A" & Rows.Count).End(xlUp).Row

For i = 4 To Lrow
StrName = ws.Cells(i, 1).Value
intComma = InStr(StrName, ",") ' this will find Comma location in string

With ws
.Cells(i, 2).Value = Mid(StrName, intComma + 2)
.Cells(i, 3).Value = Left(StrName, intComma - 1)
End With

Next i

End Sub


On this page of the site you can watch the video online How to separate words from a string with a duration of hours minute second in good quality, which was uploaded by the user Learn Excel VBA Macros 15 April 2020, share the link with friends and acquaintances, this video has already been watched 34 times on youtube and it was liked by 3 viewers. Enjoy your viewing!