簡體   English   中英

在公式中使用 VLOOKUP

[英]Using VLOOKUP in Formula

我在這一行遇到編譯錯誤,但對我來說一切似乎都是正確的。 我需要在 if 語句中放置一個 vlookup,這使得這很棘手。 有人能抓住錯誤嗎?

Dim k as Integer, numS as Integer
Range(Cells(k, 13), Cells(k, 13)).Formula = _
        "=IF(" & Range(Cells(k, 14), Cells(k, 14)).Value & "=" & VLOOKUP(""Weeks from Event " & numS-1 & " to Event " & numS & """, R11C5:R10000C8, 4) & "," & (numS) & ", """")"

我認為錯誤是 RC 表示法,嘗試 R[11]C[5]:R[10000]C[8],但要在 VBA 中使用 VlookUp,我喜歡使用 Application.WorksheetFunction...

Sub test()
    Dim k As Long
    Dim numS As Long
    Dim LookUpValue As String

    LookUpValue = "Weeks from Event " & numS - 1 & " to Event " & numS
    Debug.Print (LookUpValue)

    If (Cells(k, 14).Value = WorksheetFunction.VLookup(LookUpValue, Range(Cells(11, 5), Cells(1000, 8)), 4)) Then
        Cells(k, 13).Value = numS
    Else
        Cells(k, 13).Value = ""
    End If

End Sub

讓我知道這是否有幫助。 您可以在 VBA 編輯器中立即調出 windows (Ctrl+G) 以查看 LookUpValue 的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM