Good afternoon, I found this code on the net to change the cell contents to "Sentence Case". My problem with it, is that it is changing all cell contents to sentence case when I only want the active cell changed. The following code is in a module that is called from worksheet change event. Can some one take a look and advise.
Sub SentenceCase(rng As String)
Dim rngsource As Range
Dim cell As Range
Dim s As String
Dim Start
Dim i As Long
Dim ch As String
Set rngsource = Range(ActiveCell.address)
For Each cell In rngsource.SpecialCells(xlCellTypeConstants, 2)
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 "!"
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 If
End Select
Mid$(s, i, 1) = ch
Next i
cell.Value = s
Next cell
End Sub
Called from worksheet change event code
If Not Intersect(Target, myrange2) Is Nothing Then
SentenceCase (myrange2)
End If
Thanks
Gary