Sentence Case

To change text in a selected range to sentence case use this code. This code was supplied by Simon Huggins. He did a fine job of making the code work for both earlier & current versions of Excel. Thanks for the contribution.

Sub SentenceCase()
For Each cell In Selection.Cells
s = cell.Value
Start = True
For i = 1 To Len(s)
ch = Mid(s, i, 1)
Select Case ch
Case "."
Start = True
Case "?"
Start = True
Case "a" To "z"
If Start Then ch = UCase(ch): Start = False
Case "A" To "Z"
If Start Then Start = False Else ch = LCase(ch)
End Select
Mid(s, i, 1) = ch
cell.Value = s
End Sub

1 comment:

Anonymous said...

this code just saved me hours - thanks very much!!