excel vba force uppercase code example

Example 1: excel vba convert and entire range to uppercase

'To convert the entire worksheet range A1:C99 to UPPER case, use the 
'following VBA:

[a1:c99] = [index(upper(a1:c99),)]

'Or use this Sub:

Sub ToUpper(r As Range)
    r = Evaluate("index(upper(" & r.Address & "),)")
End Sub

'------------------------------------------------------------------------------

'To convert the entire worksheet range A1:C99 to LOWER case, use the 
'following VBA:

[a1:c99] = [index(lower(a1:c99),)]

'Or use this Sub:

Sub ToLower(r As Range)
    r = Evaluate("index(lower(" & r.Address & "),)")
End Sub

'
'
'

Example 2: excel vba to upper case

Dim sText As String
sText = "Run, forrest run"
MsgBox StrConv(sText, vbProperCase)   ' Run, Forrest Run
MsgBox StrConv(sText, vbLowerCase)    ' run, forrest run
MsgBox StrConv(sText, vbUpperCase)    ' RUN, FORREST RUN
MsgBox UCase(sText)                   ' RUN, FORREST RUN

Tags:

Vb Example