簡體   English   中英

如何修復 VBA 中的 vlookup 工作表屬性錯誤

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

我有以下代碼,運行時會在“If strF = Qualified ”行返回錯誤 1004“無法獲取 WorksheetFunction 類的 Vlookup 屬性”。 請指導如何修復。 提前致謝。

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

為什么這行代碼末尾有兩個** strResult = Application.WorksheetFunction.VLookup(Range("B3"), Sheets("Pipeline Master").Range("B6:T3000"), 6, False) ? 我試了一下,效果很好。

編輯:如果它仍然不適合您,可以嘗試使用.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