PDA

View Full Version : Solved: how to use match property of the worksheetfunction class?



maryam
05-15-2007, 02:42 AM
I use this coding:
dim i as long
for i=1 to 10
k = Application.WorksheetFunction.Match_
(Worksheets("sheet1").Range("AD" & i),_
Worksheets("sheet2").Range("B1:IV1"), 0)
next
but I get run time error 1004, unable to get the match property.
Can u help me please?:banghead:

Bob Phillips
05-15-2007, 03:03 AM
I haven't tested it, no idea what the data looks like, but this shoule be all that yiu need



Dim i As Long
For i = 1 To 10
k = Application.Match(Worksheets("sheet1").Range("AD" & i), Works, 0)
Next k

Simon Lloyd
05-15-2007, 03:20 AM
Normally your worksheet function used in VBA will still take the same form of the actual worksheet function
=Match(Lookup Value, Lookup Range,match type)
match type is false or 0 for an exact match and True or 1 for a nearest match

Simon Lloyd
05-15-2007, 03:21 AM
Ooops, didn't want to tread on toes, i see Xld has already posted!

Bob Phillips
05-15-2007, 03:23 AM
There is room for all!

maryam
05-15-2007, 04:28 AM
you mean :

k= Application.Match(Worksheets("sheet1").Range("AD" & i), Worksheets("sheet2").Range("B1:IV1"), 0)

it gives error 13, type mismatch

Simon Lloyd
05-15-2007, 05:05 AM
Thsi worked fine for me

Dim i As Integer
For i = 1 To 10
k = Application.Match(Worksheets("sheet1").Range("AD" & i), Worksheets("sheet2").Range("B1:IV1"), 0)
Next i

JKwan
05-15-2007, 12:24 PM
you mean :

k= Application.Match(Worksheets("sheet1").Range("AD" & i), Worksheets("sheet2").Range("B1:IV1"), 0)

it gives error 13, type mismatch

This will explain why you are getting an error
http://www.cpearson.com/excel/CallingWorksheetFunctionsFromVBA.htm

maryam
05-15-2007, 08:19 PM
no sorry now it works fine. I didnt have value in the worksheet cells.