Can't seem to get For loop down (index match + last row)

canyon

New Member
Joined
Jan 5, 2022
Messages
24
Office Version
  1. 2019
Platform
  1. Windows
Trying to run a forloop to iterate a formula over some cells as part of a larger bit of code. Everything runs smoothly up until this point where I get the error :

"Method 'Range' of object'_Global' failed

VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row

For i = 2 To LastRow

range("I" & i).Formula = _
    "=(INDEX(Master!$B:$B,MATCH(salesorders_1!D" & i & ",Master!$E:$E,0))"
Next i
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
No need to do that in a loop, you can do it all at once like
VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.count, "C").End(xlUp).Row


Range("I2:I" & LastRow).Formula = _
    "=INDEX(Master!$B:$B,MATCH(salesorders_1!D2,Master!$E:$E,0))"
 
Upvote 0
Solution
No need to do that in a loop, you can do it all at once like
VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.count, "C").End(xlUp).Row


Range("I2:I" & LastRow).Formula = _
    "=INDEX(Master!$B:$B,MATCH(salesorders_1!D2,Master!$E:$E,0))"
Far more simple. thank you!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top