LEFT is not an Excel macro: it is a worksheet function that returns a specified number of characters from the start of text. If you mean a VBA macro that extracts those characters, you can use VBA’s Left function inside a short macro; the worksheet formula is usually simpler when you want results to update automatically.
What LEFT means in Excel
Excel’s LEFT function takes text and returns characters beginning at the left-hand side. Its syntax is LEFT(text, [num_chars]). The square brackets indicate that num_chars is optional, not that you should type brackets into the formula. If you leave it out, Excel returns one character.
For example, with the text Northwind in cell A2, and a desire to return its first three characters, enter =LEFT(A2,3) in another cell. The result is Nor. The function does not change the source cell; it produces a result in the cell containing the formula. You can fill the formula down to process other rows.
LEFT counts characters from the beginning, including spaces and punctuation. It does not look for a word boundary or interpret a code, name, or date. If A2 contains a leading space, that space is part of what LEFT counts, even if it is hard to see in the cell.
Use the worksheet formula first
For most everyday tasks, a formula is the right tool. Formulas are visible in the worksheet, recalculate when source data changes, and do not require you to enable macros. They are useful for extracting product prefixes, postal-code segments, initials, or fixed-width fields from imported data.
With Northwind in A2 and a need for just its first character, enter =LEFT(A2) in B2. The result is N. If the number of characters should be controlled by a value in another cell, put that count in C2; with source text in A2 and the requested count in C2, enter =LEFT(A2,C2) in B2. For example, if C2 contains 4, the result is Nort.
In Microsoft 365 for Windows, type the formula in the result cell and press Enter. To copy it down, drag the fill handle, or select the formula cell and double-click its fill handle when adjacent data provides a clear boundary. Excel adjusts relative references as it fills: a formula referring to A2 normally becomes one referring to A3 in the next row.
What happens with zero, negative, and large counts
A character count of zero returns an empty text string. With Northwind in A2, =LEFT(A2,0) returns a blank-looking result. A negative count is invalid and returns the #VALUE! error. A count greater than the text length does not cause an error: Excel returns all the available text. For instance, asking for 20 characters from a nine-character word returns the whole word.
If the count comes from user input or another calculation, it is worth checking that it cannot become negative. A blank count cell can also produce a result that may surprise someone reviewing the sheet, so decide how blanks should be handled. For a basic example, with source text in A2 and a character count in C2, you could use =IF(C2<0,"Check count",LEFT(A2,C2)) in B2. This displays a message for a negative count and otherwise extracts the requested characters. The formula uses ordinary Excel functions and is suitable for Microsoft 365.
LEFT is not the same as a macro
A worksheet function is entered in a cell and returns a value there. A macro is a set of VBA instructions that performs actions, such as reading a range, writing results into another range, formatting cells, or repeating a task. The names can cause confusion because VBA also includes a Left string function. That function resembles the worksheet function, but it is used in VBA code rather than entered as a worksheet formula.
Choose a formula when you want a transparent, row-by-row result that should change as the source changes. Choose a macro when a repeatable process needs to do more than calculate a result—for example, process a report, place extracted text in a designated output column, and perform additional steps in one run. A macro is not automatically more accurate or faster for a small extraction job; it adds code that must be stored, maintained, and permitted to run.
Example VBA macro to extract three characters
The following macro reads values from column A, starting at row 2, and writes the first three characters to column B on the active worksheet. It finds the last used row in column A. Cells containing Excel errors are skipped, leaving the corresponding destination cell unchanged. Existing values in B2 and below may be overwritten, so check that column before running it.
Save a separate copy of the workbook before running a macro. VBA changes cannot be undone with Ctrl+Z, so a backup is the simplest way to recover the original state if the output is not what you intended.
Sub ExtractFirstThreeCharacters()
' Read column A and write the first three characters to column B.
Dim ws As Worksheet
Dim lastRow As Long
Dim rowNum As Long
Dim sourceText As String
Set ws = ActiveSheet
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
For rowNum = 2 To lastRow
If Not IsError(ws.Cells(rowNum, 1).Value) Then
sourceText = CStr(ws.Cells(rowNum, 1).Value)
ws.Cells(rowNum, 2).Value = VBA.Left$(sourceText, 3)
End If
Next rowNum
End Sub
Here, VBA.Left$(sourceText, 3) returns the first three characters of the string held in the variable. The dollar sign identifies the string-returning version of the VBA function. The macro converts the cell value to text with CStr before extracting characters. A number or date may therefore be treated according to its underlying value and conversion, rather than the way a custom number format displays it. If the displayed formatting matters, decide how you want to convert that value before using the macro.
How to add and run the macro
In desktop Excel for Microsoft 365 on Windows, save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if you need to keep the VBA code in that file. Press Alt+F11 to open the Visual Basic Editor, choose Insert > Module, paste the code into the module, and close or switch back to Excel. To run it, choose Developer > Macros, select ExtractFirstThreeCharacters, and click Run. If the Developer tab is not visible, enable it in Excel Options under Customize Ribbon.
On a Mac, the Developer tab also provides access to Visual Basic and Macros; keyboard shortcuts can differ by keyboard and system settings, and the function-key shortcut may require Fn. If the tab is hidden, turn on Developer in Excel’s ribbon preferences. Excel for the web can open a macro-enabled workbook, but it cannot create, edit, or run VBA macros. Use the desktop app for those tasks.
Common problems and useful checks
- The result starts with an unexpected blank: the source may contain a leading space. Check the cell contents or clean the source data before extracting characters.
- The result contains fewer characters than expected: the requested count may be too small, or the source text may be shorter than that count.
- The result is blank: the count may be zero, the source may be blank, or a formula supplying the count may return zero.
- The macro does not run: confirm you are using desktop Excel, that the workbook is saved in a macro-enabled format if the code must be retained, and that the file is trusted. Do not enable macros in files from unknown or untrusted sources.
- The macro puts results in the wrong place: it uses the active sheet and writes to column B. Activate the intended sheet and verify that column B is safe to overwrite before running it.
Another frequent misunderstanding is that LEFT extracts the first visible characters. It works with the text value Excel is handling, not necessarily the way a number or date is displayed. A date may be stored as a serial number and shown using a date format; extracting from that value may not return the first characters of the displayed date. If you need a particular display format, convert the value to text in the desired format first, then extract from that text.
Choosing between LEFT, MID, and RIGHT
LEFT is appropriate when the wanted characters begin at the start of the text. Excel’s related worksheet functions solve different positional problems: MID returns characters from a position you specify, while RIGHT returns characters from the end. For example, a fixed-width identifier with a two-character prefix and a four-character suffix may call for LEFT for the prefix and RIGHT for the suffix; a segment in the middle is a MID task.
These functions work by position, not by meaning. If a name or code has variable-length parts separated by a delimiter, a fixed character count may give inconsistent results. In that case, identify the delimiter or use a text-splitting approach suited to your Excel version rather than assuming every entry has the same structure. Check a representative sample, including short values, blanks, and unusual punctuation, before applying an extraction across a large list.
Frequently Asked Questions
Is LEFT an Excel macro?
No. LEFT is a worksheet function. VBA has a similarly named Left function that can be used inside a macro, but a formula entered in a cell is not itself a macro.
What is the formula for the first three characters?
With the text in A2, enter =LEFT(A2,3) in the cell where you want the result. It returns up to the first three characters.
Can LEFT extract the first word?
Not reliably by itself. LEFT takes a specified number of characters, while words can have different lengths. You need a method that finds the space or other delimiter, and you should account for leading spaces and entries with no delimiter.
Can I use the LEFT macro in Excel for the web?
You can use the worksheet LEFT formula in Excel for the web, but Excel for the web does not run VBA macros. Open the workbook in desktop Excel to run or edit VBA.
Why does LEFT return an error?
A negative character count returns #VALUE!. Also check whether the source cell already contains an error or whether a formula supplying the count is producing an invalid value.
Related
- Excel Attendance File to Print: Set Up and Print It
- Excel Timesheet Format: Build a Reliable Weekly Sheet
- Excel Timesheet for Multiple Employees: Setup and Tips
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Regex: Use Patterns to Find and Replace TextYes. In Excel VBA for Windows, you can use regular expressions by creating a VBScript.RegExp object, then calling…
- Do Excel Macros Work in Google Sheets?No. Excel macros written in VBA do not run in Google Sheets, and converting an Excel workbook does…
- VBA Code for Sending an Email from Excel with OutlookIn Excel for Microsoft 365 on Windows, VBA can create an email through classic Outlook using Outlook’s object…
- Excel Certifications and Macros: What Exams Actually CoverYes—some Excel certifications assess basic macro skills, but they do not all test them, and a macro task…
- SAP Analysis Excel VBA: Setup, Examples, and LimitsYes—VBA can automate SAP Analysis for Microsoft Office (often called Analysis Office or AO) from Excel, using the…
- Easy Macro Recorder in Excel: How to Record and Use OneYes. Microsoft Excel for Microsoft 365 includes a built-in macro recorder: choose Developer > Record Macro, perform the…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.