To select a cell in an Excel macro, use the Range object with a cell address or the Cells object with a row and column number, then call its Select method: Range("B4").Select or Cells(4, 2).Select. That single line is enough for a quick script you run by hand. For macros that will be run repeatedly, the more reliable approach is to skip Select entirely and act on the cell directly, for example Range("B4").Value = "Done", because Select depends on the correct sheet and window being active. Below are working patterns for both approaches, plus the pitfalls that make selection macros fail.
What You'll Need
- Excel on Windows or Mac with the Developer tab enabled (or access to the Visual Basic Editor through Tools > Macro > Visual Basic Editor on older Mac versions).
- A workbook saved as
.xlsmif you want to keep the macro after closing the file. A normal.xlsxfile silently drops macros on save. - Macro security set to allow macros. By default Excel blocks macros from files it considers untrusted, and the code simply will not run.
- Basic familiarity with the Visual Basic Editor: opening a module and pressing Run. No prior programming experience is required for the examples here.
Step-by-Step
- Enable the Developer tab. Go to File > Options > Customize Ribbon and tick Developer in the right-hand list. On Excel for Mac, use the Excel menu > Preferences > Ribbon & Toolbar. Menu wording varies slightly between versions, so look for the customization entry if the exact label differs.
- Open the editor. Click Developer > Visual Basic, or press Alt+F11 on Windows. On a Mac, use the shortcut shown in the Developer tab or the Tools > Macro menu, depending on your version.
- Insert a module. In the editor choose Insert > Module. Code placed in a module is available to the workbook as a normal macro. Code that must react to events (for example on opening the file) belongs in a worksheet or workbook code module instead, not in a standard module.
- Write the simplest selection line. Type
Sub SelectOneCell(), press Enter, then typeRange("B4").Selecton the next line. Both the quotes and the colon-free address are required;Range(B4)is a variable named B4 and will error. - Point at the right sheet first if needed. A bare
Rangeacts on the active sheet. If the macro should always work on a specific sheet regardless of what is on screen, activate it first:Worksheets("Data").ActivatethenRange("B4").Select. Using the sheet's tab name in quotes avoids the fragileActiveSheet. - Select by row and column with Cells. Replace the address with
Cells(4, 2).Selectto reach B4. Useful when the row number is calculated, for exampleCells(lastRow, 2).Select, wherelastRowis a variable you have set earlier in the macro. - Select a block of cells. Use
Range("A1:D10").Selectfor a rectangle, orRange("A1", "D10").Selectwhich does the same thing with two corner references. To select everything from A1 to the last used cell, useRange("A1").CurrentRegion.Select. - Select several separate cells. Use
Range("A1,C3,E5").Selectfor a multi-area selection. Note that the input box for typing into the selection behaves differently with non-contiguous areas. - Run the macro. Press F5 in the editor, or close the editor and use Developer > Macros, pick the macro name and click Run. If the active sheet is hidden or the workbook is protected, the selection will fail; see Troubleshooting.
- Save as a macro-enabled workbook. Use File > Save As and choose the macro-enabled format. Confirm the format prompt. Otherwise the code vanishes the next time the file is opened.
- Consider replacing Select with direct action. If the goal is to read or change a value, write to it directly:
Range("B4").Value = 100, orRange("B4").Interior.Color = vbYellow. This works without activating the sheet, is faster, and does not disturb what the user is doing.
Common Mistakes
- Selecting on the wrong sheet. The single most frequent cause of unexpected results. If the user clicks another tab before the macro runs, a bare
Range(...).Selectselects the same address on that other sheet. Always qualify the sheet by name. - Leaving out the quotes.
Range(B4)is treated as a variable, not an address. The same applies inWorksheets(Data), which must beWorksheets("Data"). - Using an address that does not exist on the sheet. Selecting A1048577 or a row past the sheet limit raises a run-time error. If row numbers are calculated, guard against zero or negative values.
- Selecting into a protected sheet or hidden sheet. Excel cannot select cells on a protected worksheet by method, and cannot activate a hidden sheet without making it visible first.
- Forgetting to unprotect before selecting. If the sheet is protected with cells locked, the macro must call
Worksheets("Data").Unprotect(with the password in quotes if one is set) and reprotect afterwards. - Selecting cells that are filtered out. A selection can include hidden rows from a filter. Combined with copy or delete, this can hit rows the user never intended to touch.
- Relying on Select for building other actions. Code that selects a cell, then selects a range, then copies, is slow and brittle. Recorded macros produce this pattern heavily; cleaning it up makes the macro far more reliable.
- Saving as .xlsx. The code runs once, then disappears on reopen because the format cannot store VBA.
Tips
- Use
Application.Goto Range("B4"), Truewhen you want Excel to scroll the sheet so the cell is visible, not just selected. The second argument brings it into view. - Use
ActiveCell.Offset(2, 1).Selectto move relative to the current cell, which is handy in loops that step through rows. - To find the last used row without hard-coding, use
Cells(Rows.Count, 1).End(xlUp).Rowand store it in a variable before selecting. - Add
Application.ScreenUpdating = Falseat the start of a long macro and set it back toTrueat the end to reduce flicker. It does not affect whether a selection works. - If the macro must select the same address across many sheets, loop the sheet names and qualify each reference rather than relying on activation.
- Test on a copy of the workbook. Selection macros that write values can overwrite data without warning.
- Comment each
Selectline with why the selection is needed. If you cannot state a reason, the line is probably unnecessary.
Troubleshooting
If the macro errors with "Select method of Range class failed", the sheet is almost certainly protected or hidden. Unhide or unprotect the sheet, then run again. If you get "Subscript out of range", the sheet name in Worksheets("...") does not match the actual tab name, including spaces and capitalisation.
If nothing happens at all, check that macros are enabled: the yellow security bar under the ribbon usually explains it, with an Enable Content button. If the editor shows code but the macro list is empty, the code may not be in a standard module, or the Sub line may be malformed.
If the selection lands on the wrong cell, verify which sheet is active at the moment the line runs. Add a temporary line such as MsgBox ActiveSheet.Name before the selection to see which sheet Excel is using. If the workbook was closed and reopened and the macro has vanished, the file was saved in the wrong format; save it again as macro-enabled.
If the macro runs slowly across many selections, the cause is usually excessive selecting. Replace each select-then-act pattern with a direct reference to the cell's value or formatting property, and keep a single Select at the very end only if the user needs to see the result.
Frequently Asked Questions
How do I select a cell in a macro without changing the active sheet?
You cannot select without making that sheet active. If you only need the value or formatting, act on the cell directly, for example Worksheets("Data").Range("B4").Value = 5, which needs no activation.
What is the difference between Range and Cells?
Range takes an address like "B4"; Cells takes a row number and a column number like (4, 2). Cells is easier when numbers are calculated; Range is easier for reading clear addresses and cell blocks.
Can a macro select a cell the user cannot see?
Only if the sheet is hidden or the row or column is hidden. Excel selects hidden worksheets only after they are made visible, and you must unprotect a protected sheet before selecting.
Why does my recorded macro select the wrong cell?
Recorded macros record the active sheet implicitly. If the active sheet differs when you run it, the address is applied there. Edit the recording to name the sheet explicitly.
Does selecting a cell inside a loop slow the macro down?
Yes. Each selection forces Excel to update the screen. For loops over many rows, write or read values through Range or Cells references directly instead of selecting.