我一直試圖將一個vlookup的結果分配給一個變量,但vlookup值實際上是一個用戶輸入,但不工作。InputData1變量沒有采用vlookup函數
我不知道我可以改變些什麼我的VBA代碼:(
它顯示我的VLOOKUP公式
Sub Info()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Dim inputData, inputData1 As String
Dim wsFunc As WorksheetFunction: Set wsFunc = Application.WorksheetFunction
Dim rngLook As Range
Set rngLook = Sheets("AutoZeroDatabase").Range("H1:I12")
Set the_sheet = Sheets("Info")
Set table_list_object = the_sheet.ListObjects("Table1")
Set table_object_row = table_list_object.ListRows.Add
inputData = InputBox("Enter a number from 1 to 12 to select a month i.e. 1 for January", "Input Box Text")
inputData1 = wsFunc.VLookup(CInt(inputData), rngLook, 2, False)
table_object_row.Range(1, 1).Value = inputData1
MsgBox ("Thank you for taking the time to update me :)")
End Sub
假設您在單元格H1:H12中有數字,請確保使用'wsFunc.VLookup(CInt(inputData),rngLook,2,False)'將'inputData'從'Variant'轉換爲Integer。 – YowE3K
或者使用一個Application.InputBox而不是一個InputBox,並使用值爲1的'Type'參數。 – YowE3K
你是男人:)。是的,該範圍的信息在第一列有數字,第二列有文字。我相信如果將變量更改爲整數,這可以被修復嗎? – Sam