You enter a number into a cell from VBA with the Range.Value property, like Range("A1").Value = 42, or with Cells(1, 1).Value = 42 if you prefer row and column numbers. The = sign puts the number into the cell exactly as typed, and the macro keeps working on it as a real number, not text. That is the short version. The long version matters because Excel and VBA both try to be helpful: they may reformat your number, store it as text, or round it based on your locale settings. The steps below cover how to enter numbers reliably, how to enter many at once, and what to do when the result looks wrong.

What You'll Need

  • Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon, then tick Developer). On Mac this is Excel > Preferences > Ribbon & Toolbar.
  • A macro-enabled workbook saved as .xlsm if you want the code to persist. A normal .xlsx will not keep macros.
  • Basic comfort with the VBA Editor (Alt+F11 on Windows, or the Developer tab > Visual Basic).
  • A backup of any worksheet whose data you are about to overwrite with a macro.

Step-by-Step

  1. Open the VBA Editor and insert a module. Press Alt+F11 on Windows (on Mac use the Developer tab > Visual Basic). In the Project Explorer, right-click your workbook, choose Insert > Module. Code typed in a module runs on any sheet; code in a sheet module only sees that sheet.
  2. Write the simplest assignment. Type the following in the module:
    Sub EnterNumber()
        Range("A1").Value = 1234.5
    End Sub
    Press F5 to run it. Cell A1 on the active sheet now holds 1234.5. This is the core technique every other example builds on.
  3. Use Cells for row and column numbers. When you loop or calculate positions, Cells(row, column) is easier than building addresses as text. Cells(5, 3).Value = 99 writes 99 into C5. Remember the order is row first, column second, which is the reverse of how people usually say a cell reference.
  4. Point at a specific sheet. Range and Cells act on whichever sheet is active, which produces wrong results if the user has clicked elsewhere. Qualify every write: Worksheets("Data").Range("B2").Value = 250. Using the sheet's CodeName, such as Sheet1.Range("B2").Value = 250, survives the sheet being renamed.
  5. Store the number in a variable first. Variables keep the code readable and let you validate before writing. For example, Dim qty As Long then qty = 12 then Range("D4").Value = qty. Choose Long for whole numbers, Double for decimals with precision, and Currency when the value is money and you need exact two-decimal arithmetic. Avoid Integer for row counts; it overflows above about 32,767.
  6. Write several numbers in one pass. To fill a block, assign an array to the range in a single statement: Range("A1:C1").Value = Array(10, 20, 30). For a vertical column, use Application.Transpose(Array(10, 20, 30)) assigned to Range("A1:A3"). This is much faster than writing cell by cell in a loop, because each cell-by-cell write is a separate call to Excel.
  7. Enter a running sequence with a loop. Dim i As Long then For i = 1 To 10: Cells(i, 1).Value = i * 5: Next i puts 5, 10, 15 up to 50 in A1:A10. If the range could be large, turn Application.ScreenUpdating off before the loop and back on afterwards to speed it up, and reset it to True in your error handler so Excel is not left in a strange state.
  8. Force a real number when text might sneak in. Values typed with a leading apostrophe, or with cell formatting set to Text before the write, can land as text. Set the number format first: Range("E1").ClearFormats or Range("E1").NumberFormat = "General" before assigning. Alternatively use Range("E1").Value2 = CDbl(SomeText) to convert explicitly, and guard it with IsNumeric(SomeText) so invalid input is caught rather than turning into an error.
  9. Control the display separately from the value. The stored number and what the cell shows are two different things. Range("F1").Value = 0.256 combined with Range("F1").NumberFormat = "0.0%" displays 25.6% while keeping the full value. Never write formatted text like "25.6%" into a cell you later calculate with.
  10. Ask the user for the number when needed. Dim n As Variant then n = InputBox("Enter a quantity") returns a string, so test it: If IsNumeric(n) Then Range("G1").Value = CDbl(n) Else MsgBox "Please enter a number". The InputBox accepts anything, including empty text, so validation is not optional.
  11. Test and save. Run the macro on a copy, check the cells show numbers right-aligned rather than left-aligned (left-aligned usually means text), then save as .xlsm. Add a comment line above each routine so you know what it does next time.

Common Mistakes

  • Writing to the wrong sheet. Unqualified Range and Cells calls target the active sheet. If a user or another macro switches sheets, the number lands somewhere unexpected.
  • Storing numbers as text. Assigning a string from a text box or a CSV import, or writing into cells preformatted as Text, leaves values that look fine but will not sum. Check alignment and use ISNUMBER() in the sheet to confirm.
  • Local decimal separators. Value interprets text using your system's regional settings, so "1,5" may break in one region and work in another. Assign real numeric values rather than text strings, or use Value2 and convert with CDbl after normalising the separator.
  • Rounding surprises. Value2 uses the underlying numeric value, which can show tiny floating-point tails like 0.30000000000000004. Round before writing when exactness matters: = Round(x, 2).
  • Forgetting Integer limits. An Integer variable overflows past about 32,767 and throws a runtime error. Use Long.
  • Leaving ScreenUpdating off. If your code errors out before resetting it, Excel can appear frozen or flickery. Always restore it.

Tips

  • Use Value2 instead of Value when you want faster writes and do not need date or currency type coercion.
  • Prefix sheet references with ThisWorkbook.Worksheets("Data") so the macro cannot accidentally hit a similarly named sheet in another open workbook.
  • Write to a named range, such as Range("InputQty").Value = 12, so moving the layout later does not break the code.
  • Keep the number formatting line directly after the value line - it makes the intent obvious and stops someone "fixing" the value to a string later.
  • For large writes, build the whole array first and assign it once. It is dramatically faster than thousands of individual cell writes.

Troubleshooting

If the macro does nothing, check that the cursor was inside the right procedure when you pressed F5, that macros are enabled for the file, and that the workbook is not protected. If you get "Compile error: Variable not defined", add Option Explicit at the top and declare every variable - it catches typos early. If you get "Application-defined or Object-defined error" on a Range line, the sheet name is probably misspelled or the sheet does not exist in that workbook; verify the exact tab name, including spaces.

If the number appears as text, clear the cell's format, set it to General, and re-run the write. If it appears with a different number of decimals than expected, you are looking at display formatting, not the stored value - apply a NumberFormat. If the value is off by a factor of 100, suspect a percentage format on the cell. If dates are wrong, remember that VBA dates are numbers with a date format applied, so assign a Date variable and set the format rather than writing a text date string.

Frequently Asked Questions

How do I put a number in a cell with VBA?

Use Range("A1").Value = 42 or Cells(1, 1).Value = 42. Both put a real number in the cell.

Why does my macro enter the number as text?

Usually the cell was formatted as Text before the write, or a string was assigned instead of a number. Clear formats, set General, and assign a numeric type.

What is the difference between Value and Value2?

Value2 returns and stores the underlying number and is faster; Value can coerce date and currency types. For plain numbers, Value2 is the safer choice.

Can I enter numbers into several cells at once?

Yes. Assign an array to a same-sized range, such as Range("A1:C1").Value = Array(1, 2, 3). It is much faster than looping.

How do I stop the macro writing to the wrong sheet?

Always qualify the reference, for example Worksheets("Data").Range("A1").Value = 1, instead of relying on the active sheet.

Can I type decimals with a comma instead of a period?

It depends on your Windows or Mac region settings. Assign real numeric values rather than text strings to avoid separator problems.