View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Luke Luke is offline
external usenet poster
 
Posts: 142
Default Problems with WorksheetFunction.Index and WorksheetFunction.Ma

Thank you for your help. I added the Dim statement and used Set as you
described. Instead of the original error message, I am now getting the
following:

Method 'Range' of object '_Worksheet' failed

"Per Jessen" wrote:

Hi

First, you should always copy/paste your original code, as typos can be a
part of the error.

In this case you have to add an sheet reference for each range/cell object
(not tested):

Dim shA As Worksheet
Set shA = Worksheets("Sheet1")
If Application.WorksheetFunction.Index(shA.Range(shA. Cells(3, 3),
shA.Cells(LastRow, 3)),
Application.WorksheetFunction.Match(Worksheets("Sh eet2").Range("A2").Offset(CurrRow,
2), shA.Range(shA.Cells(3, 1), shA.Cells(LastRow, 1)), 0), 1) = Value Then
GoTo Line

Regards,
Per

"Luke" skrev i meddelelsen
...
I've used Index and Match in Excel for some time to take a value from one
worksheet, find it on another and return a different value, looking
something
like "Index(range,Match(value,range,0),1)". I am trying to do the same
thing
in VBA, but haven't quite got the hang of it. I keep getting an
"Application-defined or object-defined error". Here's what I have (using
some abbreviations for space):

If App.WF.Index(Wkshts("Sheet1").Range(Cells(3,3),Cel ls(LastRow, 3)),
App.WF.Match(Wkshts("Sheet2").Range("A2").Offset(C urrRow,2),
Wkshts("Sheet1").Range(Cells(3,1),Cells(LastRow, 1)), 0), 1) = Value Then
GoTo Line

Feel free to point me toward a more efficient way of doing this.
Otherwise,
I would greatly appreciate it if someone could point out why VBA doesn't
like
me or my code.