I need you to write an Excel macro to automatically change uppercase to lowercase at the…
- User
I need you to write an Excel macro to automatically change uppercase to lowercase at the beginning of a cell
Assistant
Here's a well-documented Excel VBA macro that converts the first character of each selected cell to lowercase, only if it's currently an uppercase letter (A-Z). The rest of the text in the cell remains unchanged.
This macro is designed to be efficient, safe, and user-friendly, and it works on the currently selected range of cells.
✅ Macro Functionality
- Only affects text-based values (numbers, dates, or formulas remain untouched).
- Converts only the first character to lowercase if it's uppercase.
- Leaves the rest of the text unchanged.
- Skips empty or non-text cells.
- Uses
Application.ScreenUpdating = Falseto improve performance.
📌 VBA Code
Sub ConvertFirstLetterToLowercase() Dim cell As Range Dim firstChar As String Dim remainingText As String ' Turn off screen updates for faster execution Application.ScreenUpdating = False ' Loop through each selected cell For Each cell In Selection ' Only process non-empty cells If Not IsEmpty(cell) Then ' Ensure the cell contains at least one character If Len(cell.Value) >= 1 Then ' Extract the first character and the rest of the text firstChar = Left(cell.Value, 1) remainingText = Mid(cell.Value, 2) ' Check if the first character is an uppercase letter If firstChar <> LCase(firstChar) Then ' Convert the first character to lowercase and reassemble the string cell.Value = LCase(firstChar) & remainingText End If End If End If Next cell ' Turn screen updates back on Application.ScreenUpdating = True End Sub
🛠️ How to Use the Macro
-
Open the VBA Editor:
- Press
Alt + F11in Excel to open the Visual Basic for Applications (VBA) editor.
- Press
-
Insert a New Module:
- In the VBA editor, go to
Insert > Module. - Paste the macro code into the new module window.
- In the VBA editor, go to
-
Close the VBA Editor:
- Press
Alt + Qto return to Excel.
- Press
-
Run the Macro:
- Select the range of cells you want to process.
- Press
Alt + F8, selectConvertFirstLetterToLowercase, and click Run.
🔍 Example Scenarios
Original Value After Macro Run "HELLO WORLD" "hELLO WORLD" "Hello World" "Hello World" "123ABC" "123ABC" "X" "x" " Apple" " apple" "A" "a" "" (empty cell) (no change)
⚠️ Notes
- This macro does not change the case of any characters after the first character.
- It does not affect cells containing formulas, dates, or numeric values unless they are entered as strings.
- If you want to process only the first non-space character, or apply this logic to entire cells, additional logic would be needed.
This macro is ideal for formatting data like names, titles, or any text where the first letter needs to be standardized to lowercase, especially in cases where the rest of the content should remain untouched.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.