VBA & Macro Problems

How to Fix VBA Error 1004 with the Intersect Method in Excel

Phi Hung VoPhi Hung Vo Nov 2, 2026 869 views

Question details

The user is encountering VBA Run-time Error 1004 when calling the Intersect method in a Worksheet_Change event.

How to Fix VBA Error 1004 with the Intersect Method in Excel
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Writing or running a VBA macro that utilizes a Worksheet_Change event to monitor modifications within a specific named range.
Observed behavior
Run-time Error 1004 is triggered when the Intersect method evaluates an active cell that happens to be outside the monitored range, due to using 'ActiveCell' instead of the event's 'Target' parameter.
Before you start

Before modifying your worksheet's VBA code, ensure you stop any currently running macros and save a backup copy of your workbook.

Solution 1Recommended

Replace ActiveCell with the Target Parameter

Using the Target parameter ensures your code only evaluates the specific cell that was actually modified, avoiding out-of-bounds errors caused by referring to an unrelated active cell.

The Worksheet_Change event automatically passes a 'Target' range object representing the exact cells that triggered the event. When 'ActiveCell' is used inside the Intersect method, VBA may throw Error 1004 if the selection has already moved to a cell outside the expected evaluation scope (for instance, pressing Enter moves the active cell down). By referencing 'Target', the code reliably evaluates the exact range modified without throwing errors.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to launch the Visual Basic for Applications (VBA) editor.

2
Locate the Worksheet_Change Event

In the Project Explorer pane, double-click the specific Sheet module where your Worksheet_Change event code is located.

3
Identify the Intersect Statement

Find the line of code causing the error, which likely looks similar to: 'If Not Intersect(ActiveCell, Range("rangeMonths")) Is Nothing Then'.

4
Modify the Parameter

Change the word 'ActiveCell' to 'Target' so the statement reads: 'If Not Intersect(Target, Range("rangeMonths")) Is Nothing Then'.

5
Save and Test

Save your VBA project, return to the worksheet, and edit a cell to confirm that Error 1004 no longer appears.

Best Practice: Always use 'Target' inside worksheet events like Worksheet_Change or Worksheet_SelectionChange to precisely identify the user's interaction point.
Advanced Macro Support

Handle VBA Macros Smoothly with WPS Spreadsheet

WPS Office provides excellent compatibility with Microsoft Excel VBA macros. You can write, edit, and debug your VBA scripts securely and efficiently within WPS Spreadsheet.

  1. 1. Open your Workbook: Launch WPS Spreadsheet and open your macro-enabled (.xlsm) file.
  2. 2. Access the Developer Tab: Navigate to the 'Developer' tab located on the top ribbon.
  3. 3. Launch the VBA Editor: Click on 'Visual Basic' or simply press ALT + F11 to open the built-in VBA editor.
  4. 4. Edit the Macro: Apply the code fix using the 'Target' parameter as outlined, then save your changes directly within WPS.
Fully compatible with Microsoft Excel (.xlsm) macro-enabled filesBuilt-in VBA editor for seamless script debugging and codingLightweight application that executes macros quickly and efficientlyFree basic Office features with advanced developer tools
microsoft office alternative - wps office

Frequently Asked Questions

What does VBA Error 1004 mean?

Run-time error 1004 is a generic 'Application-defined or object-defined' error in VBA. In the context of the Intersect method, it typically means the ranges being compared are invalid, are located on different worksheets, or reference an inappropriate object.

Why does ActiveCell cause an error in a Worksheet_Change event?

When a user edits a cell and presses Enter, the selection cursor often moves to the next adjacent cell. The 'ActiveCell' then becomes the new cell, not the one that was just changed. If this new cell falls outside the macro's expected evaluation scope, evaluating it via the Intersect method may result in an error.

Can I use the Intersect method across different worksheets?

No, the Intersect method only works when all the referenced ranges are located on the exact same worksheet. Attempting to intersect ranges from two different sheets will trigger a run-time error.

How do I check if the Intersect method returns nothing?

You check the result using the 'Is Nothing' condition in an If statement. For example, 'If Intersect(Target, Range("A1:A10")) Is Nothing Then' means the modified cell does not overlap with the specified range of A1:A10.