Sample macro code to change the case of text in Excel
Macro to Change All Text in a Range to Uppercase Letters
Code:
Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.value)
Next
End Sub
Macro to Change All Text in a Range to Lowercase Letters
Code:
Sub Lowercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("B1:B5")
x.Value = LCase(x.Value)
Next
End Sub
Macro to Change All Text in a Cell Range to Initial Capital Letters
Code:
Sub Proper_Case()
' Loop to cycle through each cell in the specified range.
For Each x In Range("C1:C5")
' There is not a Proper function in Visual Basic for Applications.
' So, you must use the worksheet function in the following form:
x.Value = Application.Proper(x.Value)
Next
End Sub
Bookmarks