Excel VBA: Capitalize First Letter of Text
In this article
To capitalize the first letter of a cell's text in Excel VBA, use the UCase(Left(text, 1)) function on the first character and join it to Mid(text, 2) for the rest. The one-line core is UCase(Left(s, 1)) & Mid(s, 2), where s is the string you want to fix. Wrap that in a loop over your range and you have a reusable macro. Note that VBA has no built-in "proper case" worksheet function you can call directly from code, so this manual approach is the standard method, and it only touches the first character, leaving the rest of the string exactly as typed.
What You'll Need
- Microsoft Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > tick Developer, or Excel > Preferences > Ribbon & Toolbar on Mac).
- A workbook containing the text you want to change, saved as
.xlsmif you plan to keep the macro. - Basic familiarity with opening the VBA editor (Alt+F11 on Windows, Option+F11 on Mac).
- A backup copy of your data, because macros overwrite cells in place.
Step-by-Step
- Open the VBA editor. Press Alt+F11 (Windows) or Option+F11 (Mac). The editor opens in its own window. Menu labels in the editor can differ slightly by Excel version and platform, but the core commands are the same.
- Insert a module. In the editor, choose Insert > Module. A blank code pane appears. Macros placed in a standard module are available to any sheet in the workbook.
- Paste the basic function. Add this to the module:
This handles empty cells safely and leaves everything after the first character untouched.Function CapFirst(s As String) As String If Len(s) = 0 Then CapFirst = s Exit Function End If CapFirst = UCase(Left(s, 1)) & Mid(s, 2) End Function - Test it in a cell. Return to the worksheet and type
=CapFirst(A1)in an empty cell, with some text in A1. The first letter should now be uppercase. If you see#NAME?, the function is not in a standard module or macros are disabled. - Write a macro to fix a whole column. Add a second procedure to the same module:
This works on whatever range you have selected, so select the cells first, then run it.Sub CapitalizeColumn() Dim rng As Range, c As Range Set rng = Selection For Each c In rng.Cells If Not IsEmpty(c.Value) And Not IsError(c.Value) Then c.Value = UCase(Left(CStr(c.Value), 1)) & Mid(CStr(c.Value), 2) End If Next c End Sub - Run the macro. Select the target cells, press Alt+F8 (Windows) or the equivalent on Mac, choose
CapitalizeColumn, and click Run. The change happens immediately and cannot be undone with Ctrl+Z after the macro finishes, which is why the backup matters. - Decide whether you want true title case. If you want every word capitalized, not just the first, use the worksheet function instead:
Application.WorksheetFunction.Proper(c.Value). Be aware that Proper also lowercases the remaining letters, so "McDonald" becomes "Mcdonald" and "iPhone" becomes "Iphone". - Save as a macro-enabled workbook. Use File > Save As and pick Excel Macro-Enabled Workbook (
.xlsm). A plain.xlsxfile discards the code when closed.
Common Mistakes
- Using
Left(s, 1)on an empty cell. Without the length check, an empty cell can throw an error or produce odd results. Always guard withIf Len(s) = 0. - Forgetting that numbers and dates are not text. A numeric cell converted with
CStrmay reformat unexpectedly. Restrict the macro to text cells or check the cell's format first. - Assuming Proper does what you want. Proper lowercases everything after the first letter of each word, which destroys acronyms and brand names. Test on a copy before running it on a full column.
- Running the macro on the wrong selection. Because the macro uses
Selection, running it with a single cell selected only changes that cell. Select the full range first. - Saving as
.xlsx. The code vanishes on close. Use.xlsm. - Overwriting formulas. If a selected cell contains a formula, assigning
.Valuereplaces the formula with static text. Check for cells starting with=before running.
Tips
- Work on a copy of the sheet until you are confident the macro behaves correctly.
- Use
Application.ScreenUpdating = Falseat the start andTrueat the end for large ranges; it speeds up the loop noticeably. - If you only need a one-off fix, a helper column with
=UPPER(LEFT(A1,1))&MID(A1,2,999)is faster than writing code, and you can paste the results back as values. - Keep the function and the macro in the same module so both are easy to find later.
- Name your module something descriptive in the Properties window rather than leaving it as Module1.
Troubleshooting
The macro does nothing. Check that macros are enabled: File > Options > Trust Center > Trust Center Settings > Macro Settings. Also confirm you selected the cells before running.
You get a "Sub or Function not defined" error. The code is likely in a sheet module rather than a standard module, or the name is misspelled. Move it to a module inserted via Insert > Module.
Only some cells changed. Empty cells, error cells and cells containing only spaces are skipped by the guard conditions. Clear stray spaces first, or widen the check.
Text looks wrong after running. If you used Proper, acronyms will be mangled. Restore from your backup and switch to the first-letter-only method.
The workbook warns about macros on open. This is normal for .xlsm files from an unfamiliar location. Only enable content for files you created or trust.
Frequently Asked Questions
Does VBA have a built-in function to capitalize the first letter only?
No. VBA offers UCase, LCase and StrConv with vbProperCase, but none capitalizes only the first character while leaving the rest unchanged. The UCase(Left(s,1)) & Mid(s,2) pattern is the standard workaround.
What is the difference between StrConv proper case and my formula?
StrConv(s, vbProperCase) capitalizes the first letter of every word and lowercases the rest. The manual formula changes only the very first character and leaves everything else exactly as typed.
Can I undo a macro's changes?
Not with Ctrl+Z. Macro edits are not added to the undo stack. Keep a backup copy of the sheet or save before running, and you can close without saving to revert.
Will this work on Excel for Mac?
Yes. The VBA language is the same; only the keyboard shortcuts and some dialog locations differ. Use Option+F11 to open the editor and the Developer tab to access macros.
How do I capitalize the first letter of each sentence?
Split the string on periods using Split(s, "."), apply the first-letter formula to each piece, then join them back with Join. Handle the period separator carefully so you do not lose punctuation.
Can I apply this to a whole column automatically?
Yes, either by running the macro on a selected range or by placing the CapFirst formula in a helper column and copying it down. The formula approach is safer because it does not overwrite the original data.