Getting a cell's value in Excel VBA takes one line of code: the most reliable way is to read the cell through the Range object's .Value or .Value2 property, for example myValue = Range("A1").Value. This works on any Windows or Mac version of Excel that supports VBA. Below is a complete walkthrough, from opening the editor to handling dates, errors and closed workbooks.

What You'll Need

  • Excel for Windows or Mac with macros enabled (the Visual Basic Editor is included in desktop Excel; the browser version of Excel does not support VBA).
  • A workbook saved as a macro-enabled file (.xlsm) if you want to keep the code — a plain .xlsx file will strip macros when saved.
  • The Developer tab visible on the ribbon (steps below show how to enable it).

Step-by-Step

  1. Enable the Developer tab if it's missing. Right-click anywhere on the ribbon and choose Customize the Ribbon, then tick Developer in the list on the right and click OK. (Ribbon labels can differ slightly between Excel versions and platforms, but this path is the same in current desktop versions.)
  2. Open the Visual Basic Editor. Go to Developer > Visual Basic, or press Alt + F11 on Windows (on Mac, use Fn + Option + F11 or the Tools menu > Macro > Visual Basic Editor).
  3. Insert a module. In the editor's Project window, right-click your workbook's name, choose Insert > Module. A blank code window opens.
  4. Write a basic macro to read a value. Type this:

Sub GetCellValue()
    Dim myValue As Variant
    myValue = Range("A1").Value
    MsgBox myValue
End Sub

  1. Run it. Click anywhere inside the macro and press F5, or press Alt + F8 in Excel, select GetCellValue and click Run. A message box shows whatever is in cell A1 of the active sheet.
  2. Be explicit about the sheet. Range("A1") refers to the active sheet, which changes as you click around. To make the code predictable, qualify it:

myValue = Worksheets("Sheet1").Range("A1").Value

  1. Use Cells for row/column numbers. When your code calculates positions, Cells is easier:

myValue = Worksheets("Sheet1").Cells(1, 1).Value  ' row 1, column 1 = A1

  1. Read a range of cells into an array when you need many values — this is far faster than looping cell by cell:

Dim arr As Variant
arr = Worksheets("Sheet1").Range("A1:C10").Value  ' arr(1,1) holds A1's value

  1. Write the value somewhere or use it in logic. For example, copy A1's value into D1 of another sheet:

Worksheets("Report").Range("D1").Value = myValue

  1. Save your work as .xlsm. Use File > Save As and pick Excel Macro-Enabled Workbook (*.xlsm), otherwise the macro is discarded.

Common Mistakes

  • Forgetting the sheet qualifier. Range("A1") silently reads whatever sheet happens to be active. Always write Worksheets("Sheet1").Range(...) unless you genuinely mean the active sheet.
  • Using .Value on a merged cell the wrong way. Only the top-left cell of a merged range holds the value; reading the other cells returns empty.
  • Declaring the variable as the wrong type. If a cell might contain text, numbers or an error, declare the variable as Variant. Declaring it as Long or String causes a Type Mismatch error when the cell holds something else.
  • Confusing .Value with .Text. .Text returns the formatted, displayed string (so a date shows as it appears on screen), while .Value returns the underlying value. Use .Value for calculations and .Text only when you need exactly what the user sees.
  • Not enabling macros. If the workbook is opened with macros blocked, nothing runs. Click Enable Content on the security warning bar, or adjust settings via File > Options > Trust Center > Trust Center Settings > Macro Settings.
  • Saving as .xlsx. Excel warns you, but if you confirm, the macro is gone. Always use .xlsm for macro workbooks.

Tips

  • Use .Value2 instead of .Value when reading dates and doing arithmetic: it returns dates as plain serial numbers and avoids Currency/Date subtype quirks. It's also marginally faster on large reads.
  • Check for an empty cell with If IsEmpty(Range("A1").Value Then — comparing to "" misses genuinely empty cells in some cases.
  • Check for spreadsheet errors before using a value: If IsError(myValue) Then handles #N/A, #DIV/0! and friends gracefully.
  • Turn on Option Explicit (first line of the module) to catch misspelled variable names at compile time.
  • To read from a closed workbook, open it in code first (Workbooks.Open "C:\path\file.xlsm"), read the value, then close it — VBA cannot read cell values directly from a closed file without external techniques.
  • Use Dim ws As Worksheet: Set ws = Worksheets("Sheet1") once at the top, then reference ws.Range("A1") throughout — cleaner and faster.

Troubleshooting

  • "Run-time error 9: Subscript out of range" — the sheet name in your code doesn't exactly match a tab name (watch for extra spaces). Fix the name or use the sheet's index number.
  • "Run-time error 1004: Application-defined or object-defined error" — usually an invalid range reference (e.g. Range("A1:A")) or the workbook/sheet being protected. Unprotect via Review > Unprotect Sheet if you have the password.
  • "Type mismatch" error — you declared the variable as a specific type but the cell contains something incompatible. Change the declaration to Variant.
  • The macro doesn't appear in the Run dialog — you may have pasted the code into a Sheet module or ThisWorkbook instead of a standard Module, or it's a Function rather than a Sub. Move it to an inserted Module.
  • Nothing happens when pressing F5 — the cursor may not be inside the macro. Click inside the Sub first, and check the macro security settings mentioned above.
  • Macros disabled warning persists — the file was saved as .xlsx or came from the internet. Save as .xlsm, and if needed unblock the file: right-click it in File Explorer > Properties > tick Unblock.

Frequently Asked Questions

What is the basic VBA code to get a cell value?

myValue = Range("A1").Value reads A1 on the active sheet. Add a sheet name — Worksheets("Sheet1").Range("A1").Value — to make it unambiguous.

What is the difference between .Value, .Value2 and .Text?

.Value returns the underlying value (dates as Date type), .Value2 returns the same but dates as serial numbers, and .Text returns the formatted string exactly as displayed. Use .Value for most purposes.

How do I get a cell value based on variables for row and column?

Use the Cells property: myValue = Cells(rowNum, colNum).Value, where both arguments are numbers, e.g. Cells(5, 2) is B5.

How do I read a cell value from another workbook?

Reference it through the Workbooks collection: Workbooks("Book2.xlsm").Worksheets("Sheet1").Range("A1").Value — the other workbook must be open. For closed workbooks, open it in code first.

How do I store a cell value in a message box or use it in a formula?

Pass it straight in: MsgBox Range("A1").Value, or write a formula that uses it: Range("B1").Formula = "=" & Range("A1").Value * 2.

Can I get a cell value without VBA at all?

Yes — a normal formula like =Sheet1!A1 pulls a value dynamically without macros. VBA is needed only when you want the value read once, on demand, or as part of larger automation.