help with formula last row

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
What am I doing wrong here?

When I run the code I get =INDEX(RNG2,MATCH(G2,RNG3,0)) in Z2
What I'm trying to get is =INDEX(AL2:AL21182,MATCH(G2,AM2:AM21182,0))

VBA Code:
Dim rng, rng2, rng3 As Range, a, i As Long

 Set rng = Range("W2")
 Set rng2 = Range("AL2:AL" & Range("AL" & Rows.Count).End(xlUp).Row)
 Set rng3 = Range("AM2:AM" & Range("AL" & Rows.Count).End(xlUp).Row)
    
 If rng.Offset(0, 1).Value = 1 Then
    Range("Z2") = "=INDEX(" & rng2 & ",MATCH(G2," & rng3 & ",0))"

I also tried it like this
VBA Code:
    Range("Z2") = "=INDEX(rng2,MATCH(G2,rng3,0))"

Thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try it like
VBA Code:
Range("Z2") = "=INDEX(" & rng2.address & ",MATCH(G2," & rng3.address & ",0))"
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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