How to use UCase function in VBA?

In VBA (Visual Basic for Applications), the UCase function converts a specified string to uppercase.

Basic syntax

VBA

UCase(String)
Where String is the string expression you want to convert to uppercase.

Example

VBA

Sub ConvertToUppercase()
    Dim originalText As String
    Dim uppercaseText As String

    originalText = "Hello, World!" ' Input string
    uppercaseText = UCase(originalText) ' Convert to upper case

    MsgBox uppercaseText ' Display the result in a message box
End Sub
The UCase function is useful when you want to perform case-insensitive string comparisons or ensure that text is formatted consistently in uppercase. Remember that UCase will not modify any non-letter characters, so numbers, punctuation, and spaces will be unaffected. Note that VBA also has the opposite function called LCase which converts text to lowercase.

Unlock Your Potential

Excel

Basic - Advanced

Access

Access Basic - Advanced

Power BI

Power BI Basic - Advanced

Help us grow the project