Resolving 424 'Object Required' on VBA Index/Match formula

frateg8r

Board Regular
Joined
Mar 2, 2005
Messages
221
Office Version
  1. 365
Platform
  1. Windows
I created a VBA version of this successful formula:
Code:
=INDEX([DATA.xlsm]FIRMS!$K:$K,MATCH(Home!L19,[DATA.xlsm]FIRMS!$A:$A,0),1)

The script that I produced based on that is:
Code:
 RecipientStr = Application.WorksheetFunction.Index(Workbooks(Data.xlsm).Sheets("FIRMS").Range("K:K"), Application.WorksheetFunction.Match(ThisWorkbook.Sheets("Home").Range("L19").Value, Workbooks(Data.xlsm).Sheets("FIRMS").Range("A:A"), 0), 1)

However, that produces, as indicated in the title, a Runtime 424 error, "Object Required". This is my first attempt at creating a formula via VBA, and with that error and some of the stuff I've found online looking for an answer, I'm feeling a bit over my head.

Can anyone offer a suggestion as to what I'm overlooking here?

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You were very close. Put quotes around the workbook name.
Workbooks("Data.xlsm")

Try something like this using a With code block to shorten it a bit.
Code:
[color=darkblue]With[/color] Workbooks("Data.xlsm").Sheets("FIRMS")
    RecipientStr = Application.Index(.Range("K:K"), Application.Match(ThisWorkbook.Sheets("Home").Range("L19").Value, .Range("A:A"), 0), 1)
[color=darkblue]End[/color] [color=darkblue]With[/color]

Also in this instance, the INDEX function could be eliminated in VBA.
Code:
[color=darkblue]With[/color] Workbooks("Data.xlsm").Sheets("FIRMS")
    RecipientStr = .Range("K" & Application.Match(ThisWorkbook.Sheets("Home").Range("L19").Value, .Range("A:A"), 0))
[color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0
I created a VBA version of this successful formula:
Code:
=INDEX([DATA.xlsm]FIRMS!$K:$K,MATCH(Home!L19,[DATA.xlsm]FIRMS!$A:$A,0),1)

The script that I produced based on that is:
Code:
 RecipientStr = Application.WorksheetFunction.Index(Workbooks(Data.xlsm).Sheets("FIRMS").Range("K:K"), Application.WorksheetFunction.Match(ThisWorkbook.Sheets("Home").Range("L19").Value, Workbooks(Data.xlsm).Sheets("FIRMS").Range("A:A"), 0), 1)

However, that produces, as indicated in the title, a Runtime 424 error, "Object Required". This is my first attempt at creating a formula via VBA, and with that error and some of the stuff I've found online looking for an answer, I'm feeling a bit over my head.

Can anyone offer a suggestion as to what I'm overlooking here?

Thanks
You need quotation marks on your "Data.xlsm" file name. Both places.
 
Upvote 0
Thanks guys - appreciate the feedback. I'm not surprised I missed something relatively obvious.

And AlphaFrog - thanks for the tips on how to improve the code. I'll have to work on that.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

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