Convert Index/match to vba

JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
127
Office Version
  1. 365
Hello,

I am having trouble converting the following excel function to vba:
=INDEX('Product Selector'!F13:F18,MATCH(Specify!B10,'Product Selector'!A13:A18,0),1)

The vba code I have is as follows:
iRowNo = 10
For i = 1 To lr
x = Application.WorksheetFunction.Index(Sheets("Product Selector").Range("A13:A100") _
, Application.WorksheetFunction.Match(Sheets("Specify").Cells(iRowNo, 2), Sheets("Product Selector").Range("F3:F100"), 0), 1)

If Not (IsError(x)) Then
Worksheets("Specify").Cells(iRowNo, 4).Value = x
End If
iRowNo = iRowNo + 1
Next i

I keep getting a run-time error '1004'
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try removing the two WorksheetFunction in the formula
 
Upvote 0
What have you declared x as ?
 
Upvote 0
It needs to be Variant, also the ranges in the formula don't match up, you have A13:A100 & F3:F100
 
Upvote 0
The range A13:A100 is the range that has the match lookup, the range F13:F100 is the data I want to return from the index as per the excel formula =INDEX('Product Selector'!F13:F18,MATCH(Specify!B10,'Product Selector'!A13:A18,0),1)
 
Upvote 0
Compare that formula to the one in the code.
They are very different!
 
Upvote 0
Give this a go
Code:
Sub jannetteChristie()
   Dim x As Variant
   Dim Pws As Worksheet, Sws As Worksheet
   
   Set Pws = Sheets("Product Selector")
   Set Sws = Sheets("Specify")
   iRowNo = 10
   For i = 1 To 10
      With Application
         x = .Index(Pws.Range("F13:A100"), .Match(Sws.Cells(iRowNo, 2), Pws.Range("A13:A100"), 0))
      End With
      If Not IsError(x) Then
         Sws.Cells(iRowNo, 4).Value = x
      End If
      iRowNo = iRowNo + 1
   Next i
End Sub
 
Upvote 0
Morning,
Thanks for your reply - when I use the code the "Specify" sheet is not being updated, it is returning an error every time
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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