JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
119
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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