I've read all the other posts about this but still don't understand what I'm doing wrong. To minimize confounders, I've reduced my spreadsheet to the minimum:
- Sheet1 has 2 dates, one in B1 and one in B2
- Sheet2 has the same 2 dates in A1 and A2
My code is:
Public Sub GetPymtEffDate()
Dim x As Variant
Dim LookupValue As Variant
Dim LookupArray As Range
Worksheets("Sheet1").Activate
LookupValue = Worksheets("Sheet1").Cells(ActiveCell.Row, 2)
Set LookupArray = Worksheets("Sheet2").Range("a1:a2")
MsgBox LookupValue
x = Application.WorksheetFunction.Match(LookupValue, LookupArray, 1)
MsgBox x
End Sub
The idea is that if the ActiveCell is on row 1 of Sheet1, for example, it'll go find that same date on Sheet2. The first MsgBox works fine, but it gives an error on the Match function, even though I know the date is there.
What am I doing wrong? (is there an icon for beating my head against a wall?)
=MATCH(B1,Sheet2!A$1:A$2)
into D1 and D2 on Sheet1, it returns the correct position of the dates on Sheet2 – OutThere May 2 '15 at 15:44