在vba中使用匹配公式返回行号

时间:2017-08-11 08:46:20

标签: vba

我已经尝试了很长时间了,虽然我得到了正确的答案,但我得到了Application-defined or Object defined error

我有两张纸:Sheet2和Sheet3。两张纸都有一列“url”。我想要的是获取Sheet2中的网址行号并打印网址行位置 Sheet3的C列(“匹配行”)。

这是我正在处理的数据的示例。 This is the Sheet3 which has url in the column B and Match Row in Column C This is the Sheet2 which has url in the column B

我在此行中收到错误

Matchvalue.Formula = "=Match(Worksheets("Sheet3").Cells(i, 2), Worksheets("Sheet2").Range("B:B"), 0)

这是我尝试过的:

Dim i As Integer

i = 2

Do While Worksheets("Sheet3").Cells(i, 2) <> ""

    Worksheets("Sheet3").Cells(i, 14) = 
    WorksheetFunction.Match(Worksheets("Sheet3").Cells(i, 2), 
    Worksheets("Sheet2").Range("B:B"), 0)
    i = i + 1

Loop

1 个答案:

答案 0 :(得分:0)

我没有使用Match,所以我不知道它的签名但是: 通过逃避行情也许......就像

一样
Matchvalue.Formula = "=Match(" & Worksheets("Sheet3").Cells(i, 2) & ";B:B;0)"

要逃避报价,只需加倍。

例如Debug.print "Hey ""You"" how are you ?"