Microsoft Office Tutorials and References
In Depth Information
Changing the Case of Text
End If¶
On Error Resume Next¶
Set Rng = .SpecialCells(xlCellTypeConstants, xlTextValues)¶
On Error GoTo 0¶
End If¶
If Rng Is Nothing Then¶
MsgBox "No text was found in the current selection", _¶
Exit Sub¶
End If¶
End With¶
'Check the first cell in that range to see what must be done¶
Select Case Rng(1).Value¶
Case UCase$(Rng(1).Value)¶
'Change to sentence case¶
Conversion = 2¶
Case UCase$(Left$(Rng(1).Value, 1)) & _¶
LCase$(Mid$(Rng(1).Value, 2))¶
'Change to lowercase¶
Conversion = 3¶
Case LCase$(Rng(1).Value)¶
'Change it directly to Upper ?¶
If UCase$(Left$(Rng(1).Value, 1)) & _¶
LCase$(Mid$(Rng(1).Value, 2)) = _¶
Application.Proper(Rng(1).Value) Then¶
'Proper and Sentence are equal, change to Upper¶
Conversion = 1¶
'Change to proper case¶
Conversion = 4¶
End If¶
Case Else¶
'Change to uppercase¶
Conversion = 1¶
End Select¶
'Turn off screen updating¶
Application.ScreenUpdating = False¶
'Change the cells, according to what needs to be done¶
For Each Cll In Rng.Cells¶
Select Case Conversion¶
Case 1 'changes to UPPER CASE¶
Cll.Value = UCase$(Cll.Value)¶
Case 2 'changes to Sentence Case¶
Cll.Value = UCase$(Left$(Cll.Value, 1)) & _¶
LCase$(Mid$(Cll.Value, 2))¶
Case 3 'changes to lower case¶
Cll.Value = LCase$(Cll.Value)¶
Case 4 'Changes to Proper Case¶
Cll.Value = Application.Proper(Cll.Value)¶
End Select¶
Search JabSto ::

Custom Search