Coding⏱️ 3 min read📅 2026-06-19

How to Fix: VBA Excel: Error during range selection during workbooks iteration

Error in VBA Excel code when selecting ranges from multiple workbooks.

Quick Answer: Use the `Range.Find` method with the `xlPart` argument to find the range, and then use the `Offset` method to adjust for the column offset.

Error during range selection in VBA Excel: The macro is attempting to select a range of cells based on the 'Part Number' column, but it encounters an error due to incorrect usage of the Range object. This issue affects users who have workbooks with varying column positions and row counts for the 'Part Number' column.

This error can be frustrating as it prevents the macro from completing its intended task. However, by following the steps outlined below, you should be able to resolve this issue and continue working on your project.

⚠️ Common Causes

  • The primary reason for this error is the incorrect usage of the Range object. The macro is trying to select a range of cells using the 'rangestart' and 'rangefinish' variables, which are not properly formatted as Range objects.
  • Another possible cause is that the 'Part Number' column does not exist in every workbook or has varying column positions and row counts, causing the macro to fail when trying to select the range.

✅ Best Solutions to Fix It

Correctly format the Range object

  1. Step 1: In the line where the error occurs, replace 'rangestart' with the full address of the cell containing the 'Part Number', including column letter and row number (e.g., 'A2').
  2. Step 2: Replace 'rangefinish' with the full address of the last cell in the range, including column letter and row number. To do this, use the 'lastrow' variable to get the last row number and then use the 'Cells(lastrow, lastcolumn)' function to get the last cell's address.
  3. Step 3: Make sure to adjust the column numbers and row numbers according to the actual positions of the 'Part Number' column in each workbook.

Verify column position and row count

  1. Step 1: Before attempting to select the range, verify that the 'Part Number' column exists in every workbook and has a consistent column position.
  2. Step 2: Use the 'UsedRange.Find' function to find the first occurrence of the 'Part Number' string in each workbook. This will ensure that you are selecting the correct range.

✨ Wrapping Up

By following these steps, you should be able to resolve the error and continue working on your project. Remember to carefully verify the column position and row count for the 'Part Number' column in each workbook to avoid similar errors in the future.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions