To enter text into a cell with Excel VBA, you assign a string to the cell's .Value property, for example Range("A1").Value = "Hello". That single line writes text instantly, without selecting the cell or typing. You can target one cell, a whole range, a cell on another sheet, or a cell that moves as your data grows. Everything below assumes you know how to open the Visual Basic Editor (Alt+F11 or the Developer tab) and insert a module, where you paste the code.

What You'll Need

  • Excel on Windows or Mac with macros enabled. On Windows, the Developer tab appears via File > Options > Customize Ribbon; on Mac, via Excel > Preferences > Ribbon & Toolbar. Menu labels can differ slightly by version and platform.
  • A workbook saved as .xlsm (macro-enabled) if you want the code to be kept. A plain .xlsx file discards macros on save.
  • Macro security relaxed enough to run your own code. If macros are blocked you will see a security warning bar; do not disable protection for files from unknown sources.
  • A working knowledge of the address of the cells you want to fill, such as A1 or A1:C10.

Step-by-Step

  1. Open the editor. Press Alt+F11 (Windows) or Fn+Alt+F11 (some Mac keyboards), or click Developer > Visual Basic.
  2. Insert a standard module. In the editor choose Insert > Module. A blank code window appears. Code in a standard module can run from anywhere; code in a worksheet module only runs in response to events on that sheet.
  3. Write a simple procedure. Type:
    Sub EnterText()
        Range("A1").Value = "Order confirmed"
    End Sub
    The quotes are required. Without them VBA thinks you are referring to a variable or command and throws a compile error.
  4. Run it. Click anywhere inside the procedure and press F5, or use Run > Run Sub/UserForm. Switch back to Excel with Alt+F11 and check cell A1. The text is now there.
  5. Target a whole range at once. Replace the range with Range("A1:A10").Value = "Pending". Every cell in the range receives the same text in one statement, which is far faster than looping.
  6. Write to a specific sheet. Qualify the sheet so the code does not depend on which sheet is active: Worksheets("Report").Range("B2").Value = "Draft". If the sheet name contains a space, keep the quotes around it; if you rename the sheet later, update the code or it fails with a subscript out of range error.
  7. Add line breaks or special characters. Use Chr(10) for a line break inside a cell, for example "Line one" & Chr(10) & "Line two". Turn on wrapping with Range("A1").WrapText = True, or the break will be stored but not visible.
  8. Preserve leading zeros and long numbers. If the text looks like a number (a phone number or product code), prefix the cell format as text first with Range("A1").NumberFormat = "@", then assign the value. Otherwise Excel may strip leading zeros or convert the entry into a number or date.
  9. Append instead of overwrite. To add to existing content, use Range("A1").Value = Range("A1").Value & " - updated". On an empty cell this produces a leading separator, so check first with If Len(Range("A1").Value) > 0 Then.
  10. Find the next empty row. Common approach: Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Value = "New entry". This starts at the bottom of column A and jumps up to the last used cell, so your text lands directly beneath the data.
  11. Save and test. Press Ctrl+S. Run the macro again and confirm it behaves the same on a second run. If it appends rows, that is expected; if it overwrites, that is expected too, because you told it to.

Common Mistakes

Forgetting quotation marks. The most frequent error. Text in VBA must be inside double quotes; a bare word is treated as a variable name.

Quoting a quote. To put a double quote inside a string, double it: "He said ""yes""".

Relying on the active sheet. Unqualified Range calls act on whatever sheet happens to be active. Always name the worksheet when the code touches more than one sheet.

Assuming the value is text. Assigning "1/2" or "00123" to a General-formatted cell can yield a date or a number. Set NumberFormat = "@" first if the string must stay as typed.

Writing into protected sheets. If the sheet is protected, assignment fails. Unprotect programmatically only if you know the password and it is your own workbook.

Editing the wrong module. Code pasted into ThisWorkbook or a sheet module may not appear in the macro list the way you expect.

Tips

Use Range("A1").Value2 when working with dates or large volumes of numbers; it skips some formatting overhead and is faster in loops.

Assign from an array when writing many different values: build a variant array and assign it to a same-sized range in one pass. This is dramatically quicker than writing cell by cell.

Turn off Application.ScreenUpdating at the start of long procedures and restore it to True at the end, including in an error handler, so the screen is not redrawn on every write.

Use = for the value and .Formula only when you genuinely want Excel to parse a formula string. If your text begins with an equals sign, prefix it with an apostrophe or format the cell as text to stop Excel treating it as a calculation.

Keep a short status message via MsgBox at the end of test runs so you can tell whether the macro finished or stopped early.

Troubleshooting

Compile error: expected expression. Usually a stray quote, a missing Then after If, or text not wrapped in quotes. Click Debug and the offending line is highlighted.

Run-time error 9, subscript out of range. The worksheet name in your code does not match a sheet in the workbook. Check spelling, including spaces, and confirm the sheet has not been renamed.

Run-time error 1004. Often a protected sheet, a misspelled range address, or an invalid reference. Verify the address and protection state.

Nothing happens at all. Macros may be disabled. Check the security warning bar and your Trust Center macro settings, and confirm you saved as .xlsm.

Text appears with a green triangle or is flagged as an error. Excel is warning that a number is stored as text. That is normal if the text is a code; you can ignore the warning or use the error-checking options to suppress it.

The value changes format unexpectedly. Pre-format the cell with NumberFormat = "@" before assigning.

Frequently Asked Questions

How do I enter text without overwriting what is already there?

Read the existing value and concatenate: Range("A1").Value = Range("A1").Value & newText, or use the next empty row technique shown above.

Can I put a line break inside a cell with VBA?

Yes. Use Chr(10) between the pieces of text and set WrapText = True so the break is displayed.

Why does my text show as a number or date?

The cell was formatted as General and Excel interpreted the string. Set the number format to text before writing, or prefix the entry with an apostrophe.

How do I put text into a cell on another sheet?

Qualify the range with the worksheet object, such as Worksheets("Sheet2").Range("A1").Value = "text". The sheet does not need to be active.

Does this work on Excel for Mac?

Yes, the object model for writing text is the same. Keyboard shortcuts and some developer settings differ; use the Developer tab to open the editor if the shortcut does not respond.

Can I write text into a merged cell?

Yes, but assign to the top-left cell of the merged area, not the others, or you may receive a run-time error.