View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1462_] Rick Rothstein \(MVP - VB\)[_1462_] is offline
external usenet poster
 
Posts: 1
Default convert second word in range to Proper when first variable length - urgent please

Just two little hiccups - my fault - didn't mention it
apostrophe surnames & hyphenated:
e.g. O'Brien-Radford (required) -
got O'brien-radford.


So, you lied to me... there was another linking character and/or anomaly,
huh?<g No problem... as it turns out, I had left a statement out of the
code I posted which means no hyphenated name would have been handled
correctly. Replace all the code I gave you in my other response with the
following code which will handle names with apostrophes and dashes
correctly. You can run the macro against your existing data even if it
contains properly formatted names... the routine will simply replace
correctly formatted names with itself; but, in the meantime, it will
straighten out dashed and apostrophe'd names.

Sub MakeNamesProper()
Dim X As Long
Dim LastRow As Long
Dim Apostrophe As Long
Dim Text As String
Dim Parts() As String
With Worksheets("Sheet3")
LastRow = .Cells(Rows.Count, "D").End(xlUp).Row
For X = 1 To LastRow
Text = .Cells(X, "D").Value
Parts = Split(Text, "&")
IndividualName Parts(0)
If InStr(Text, "&") Then IndividualName Parts(1)
Text = Join(Parts, "&")
If InStr(Text, "'") Then
Apostrophe = InStr(Text, "'")
Mid(Text, Apostrophe + 1) = UCase(Mid(Text, Apostrophe + 1, 1))
End If
.Cells(X, "D").Value = Text
Next
End With
End Sub

Sub IndividualName(Text As String)
Dim Dash As Long
Dim Space As Long
Text = StrConv(Text, vbProperCase)
If InStr(Text, "-") Then
Dash = InStr(Text, "-")
Mid(Text, Dash) = " "
Text = StrConv(Text, vbProperCase)
Mid(Text, Dash) = "-"
End If
Space = InStr(Text, " ")
Mid(Text, 1) = UCase(Left(Text, Space - 1))
End Sub

Rick