简体   繁体   English

如何修复 VBA 中的 vlookup 工作表属性错误

[英]how to fix vlookup worksheet property error in VBA

I have the following code which when run, returns error 1004 "Unable to get Vlookup Property of the WorksheetFunction Class" on the line "If strF = Qualified ".我有以下代码,运行时会在“If strF = Qualified ”行返回错误 1004“无法获取 WorksheetFunction 类的 Vlookup 属性”。 Please guide how to fix.请指导如何修复。 Thanks in advance.提前致谢。

Sub Geo()

Dim i As Long
Dim strB As String, strF As String, strResult As String

For i = 1 To 100

With ActiveSheet
strB = .Cells(i, 2).Value2
strF = .Cells(i, 6).Value2
End With

If strB = vbNullString Then
strResult = vbNullString

Else
If strF = "Qualified" Then
strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("Pipeline Master").Range("B6:T3000"), 6, False)**

On Error Resume Next
strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("2019-Wins&Losses").Range("A7:M5000"), 2, False)

On Error Resume Next
strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("PipelineHistory").Range("C3:G15934"), 5, False)

On Error Resume Next

strResult = " "
On Error GoTo 0

End If
End If

ActiveSheet.Cells(i, 11).Value2 = strResult
Next i

End Sub

Why do you have two ** at the end of this code line strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("Pipeline Master").Range("B6:T3000"), 6, False) ?为什么这行代码末尾有两个** strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("Pipeline Master").Range("B6:T3000"), 6, False) ? I tried it out and it worked fine.我试了一下,效果很好。

edit: If it still doesn't work for you maybe try to use the .formula property instead.编辑:如果它仍然不适合您,可以尝试使用.formula属性。

With ThisWorkbook.Worksheets("Pipeline Master").Range("B3")
    .Formula = "=VLOOKUP(""Qualified"",B6:T3000,6,FALSE)"
    .Value = .Value
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM