I am trying to make macro to add dashes between all the letters in a word. I want to have names be spelled out with dashes between them. I do not want the name to be automatically upper case. I have a found a macro online that is similar to what I want to do and have attempted to edit it to make it do what want it to do. Every time I edit it, the If statement starting on line 17 throws a break error.
Sub CapDashNames()
Dim sTemp As String
Dim sName As String
Dim J As Integer
sTemp = UCase(Selection.Range.Text) ' Make all uppercase
If Len(sTemp) > 1 Then
sName = ""
For J = 1 To Len(sTemp) - 1
' Add new character to name
sName = sName & Mid(sTemp, J, 1)
If Mid(sTemp, J, 1) >= "A" And Mid(sTemp, J, 1) <= "Z" Then
' Add a dash if character was a letter
sName = sName & "-"
Else
' Character added was not a letter
If Mid(sName, Len(sName) - 1, 1) = "-" Then
' If there is a dash just before non-letter,
' get rid of it
sName = Left(sName, Len(sName) - 2)
sName = sName & Mid(sTemp, J, 1)
End If
End If
Next J
' Add final character
sName = sName & Right(sTemp, 1)
Selection = sName
End If
End Sub