VBA动态范围VLOOKUP

时间:2018-02-14 18:30:28

标签: excel-vba vba excel

我是VBA的新手,需要获得VLOOKUP的帮助吗?

我不断收到预期的编译错误:声明结束

这是给我带来问题的路线。

我添加了&在(row_number)之后签名并且我现在得到运行时错误'9':下标超出范围错误。

Sheets("WIP Count").Range("G" & (row_number)).Formula = "=VLOOKUP(C" & (row_number) & ",PRISM!L:T,8,FALSE)"

这是代码的其余部分。

Sub CommandButton1_Click()
q1_answer = Sheets("Tracker").Range("F8")
q2_answer = Sheets("Tracker").Range("F9")
q3_answer = Sheets("Tracker").Range("F10")
q4_answer = Sheets("Tracker").Range("F11")

    If q1_answer = "" Then
        MsgBox "Fill in Name"
        Exit Sub
    End If

     If q2_answer = "" Then
        MsgBox "Fill in Serial Number"
        Exit Sub
    End If

     If q3_answer = "" Then
        MsgBox "Fill in Part Number"
        Exit Sub
    End If

     If q4_answer = "" Then
        MsgBox "Fill in Quantity"
        Exit Sub
    End If


row_number = 1
Do
DoEvents
row_number = row_number + 1
    item_in_review = Sheets("WIP_Count").Range("A" & row_number)

Loop Until item_in_review = ""

last_transaction_id = Sheets("WIP_Count").Range("A" & (row_number - 1))

Dim next_transaction_id As Integer
next_transaction_id = last_transaction_id + 1

Sheets("WIP_Count").Range("A" & (row_number)) = next_transaction_id
Sheets("WIP_Count").Range("B" & (row_number)) = q1_answer
Sheets("WIP_Count").Range("C" & (row_number)) = q2_answer
Sheets("WIP_Count").Range("D" & (row_number)) = q3_answer
Sheets("WIP_Count").Range("E" & (row_number)) = q4_answer
Sheets("WIP_Count").Range("F" & (row_number)).Value = Date
Sheets("WIP Count").Range("G" & (row_number)).Formula = "=VLOOKUP(C" & (row_number) & ",PRISM!L:T,8,FALSE)"

Sheets("Tracker").Range("F8") = ""
Sheets("Tracker").Range("F9") = ""
Sheets("Tracker").Range("F10") = ""
Sheets("Tracker").Range("F11") = ""

MsgBox "Done"

End Sub

0 个答案:

没有答案