shyamvinjamuri
Board Regular
- Joined
- Aug 2, 2006
- Messages
- 175
split a name into first and last name based on upper and lower case.
eg. JohnDoe to read as John Doe.
Please help
Thanks
eg. JohnDoe to read as John Doe.
Please help
Thanks
Excel Workbook | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | JohnDoe | John | Doe | ||
2 | MikeWilford | Mike | Wilford | ||
3 | JaniceDoe | Janice | Doe | ||
4 | MichaelWilford | Michael | Wilford | ||
5 | JohnDoe | John | Doe | ||
6 | MikeWilford | Mike | Wilford | ||
7 | JaniceDoe | Janice | Doe | ||
8 | MichaelWilford | Michael | Wilford | ||
Sheet2 |
Look at the blue bar at the top of the page and click Quick Links|Subscribed Threads.I could not find my previous post
Excel Workbook | |||
---|---|---|---|
A | |||
1 | JohnDoe | ||
2 | MikeWilford | ||
3 | JaniceDoe | ||
4 | MichaelWilford | ||
5 | JohnDoe | ||
6 | MikeWilford | ||
7 | JaniceDoe | ||
8 | MichaelWilford | ||
9 | |||
Sheet1 |
Excel Workbook | |||
---|---|---|---|
A | |||
1 | John Doe | ||
2 | Mike Wilford | ||
3 | Janice Doe | ||
4 | Michael Wilford | ||
5 | John Doe | ||
6 | Mike Wilford | ||
7 | Janice Doe | ||
8 | Michael Wilford | ||
9 | |||
Sheet1 |
Option Explicit
Sub SplitName()
' hiker95, 03/04/2011
' http://www.mrexcel.com/forum/showthread.php?t=533666
Dim c As Range, a As Long, H As String
Application.ScreenUpdating = False
For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp))
H = Trim(c)
For a = 2 To Len(H) Step 1
If Asc(Mid(H, a, 1)) > 64 And Asc(Mid(H, a, 1)) < 91 Then
c = Left(H, a - 1) & " " & Right(H, Len(H) - a + 1)
Exit For
End If
Next a
Next c
Application.ScreenUpdating = True
End Sub
Option Explicit
Private Sub Worksheet_Calculate()
Call InsertSpaces
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Call InsertSpaces
End Sub
Private Sub InsertSpaces()
Const sNameColumn As String = "A" [COLOR=green]' column containing name[/COLOR]
Dim iLast As Long
Dim iRow As Long
Dim iChar As Integer
Dim iByte1 As Byte
Dim iByte2 As Byte
Dim sTemp As String
Application.EnableEvents = False
iLast = Cells(Rows.Count, sNameColumn).End(xlUp).Row
For iRow = 1 To iLast
Cells(iRow, sNameColumn) = Replace(Cells(iRow, sNameColumn), " ", "")
sTemp = Left(Cells(iRow, sNameColumn), 1)
For iChar = 2 To Len(Cells(iRow, sNameColumn))
iByte1 = Asc(Mid(Cells(iRow, sNameColumn), iChar - 1, 1))
iByte2 = Asc(Mid(Cells(iRow, sNameColumn), iChar, 1))
If iByte1 >= Asc("a") And iByte1 <= Asc("z") And iByte2 >= Asc("A") And iByte2 <= Asc("Z") Then
sTemp = sTemp & " " & Chr(iByte2)
Else
sTemp = sTemp & Chr(iByte2)
End If
Next iChar
Cells(iRow, sNameColumn) = sTemp
Next iRow
Application.EnableEvents = True
End Sub
Excel Workbook | ||||
---|---|---|---|---|
A | B | |||
1 | JohnDoe | John Doe | ||
2 | MikeWilford | Mike Wilford | ||
3 | JaniceDoe | Janice Doe | ||
4 | MichaelWilford | Michael Wilford | ||
5 | JohnDoe | John Doe | ||
6 | ThomasMichaelSmith | Thomas Michael Smith | ||
7 | PPJones | P P Jones | ||
8 | PaulKDWalker | Paul K D Walker | ||
9 | MichaelJFox | Michael J Fox | ||
10 | JohnSmith-Jones | John Smith-Jones | ||
11 | John Smith | John Smith | ||
Split Names 1 Cell |
Excel Workbook | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | JohnDoe | John | Doe | |||
2 | MikeWilford | Mike | Wilford | |||
3 | JaniceDoe | Janice | Doe | |||
4 | MichaelWilford | Michael | Wilford | |||
5 | JohnDoe | John | Doe | |||
6 | MikeWilford | Mike | Wilford | |||
7 | JaniceDoe | Janice | Doe | |||
8 | MichaelWilford | Michael | Wilford | |||
9 | ThomasMichaelSmith | Thomas | Michael | Smith | ||
10 | PPJones | P | P | Jones | ||
11 | MichaelJFox | Michael | J | Fox | ||
12 | JohnSmith-Jones | John | Smith-Jones | |||
13 | John Smith | John | Smith | |||
Split Names Multiple Cells |