View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Convert list to UPPER, lower & Proper cases.

Here's my collection of case conversion subs, which you'll see have
been configured to work on selected cells. You could easily modify
these to accept a range *and/or* convert to a function so they return a
string. (I use them 'as is' for updating selected cells on-the-fly)


Sub ProperCase()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection: c.value = Application.Proper(c.value): Next
End Sub

Sub UpperCase()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection: c.value = UCase(c.value): Next
End Sub

Sub LowerCase()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection: c.value = LCase(c.value): Next
' For Each c In Selection: c.Value = UCase(Left(c.Value, 1)) &
LCase(Mid(c.Value, 2)): Next
End Sub

Sub SentenceCase()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Selection.Cells
s = c.value
Start = True
For i = 1 To Len(s)
Ch = Mid(s, i, 1)
Select Case Ch
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
Next
c.value = s
Next
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion