【发布时间】:2017-07-15 20:18:39
【问题描述】:
我从用户那里获取输入,并使用此输入从另一个工作簿中使用 vlookup。但是我无法获得正确的值,总是 #value 错误
Option Explicit
Sub SıraNo()
Dim ResimNo As Long
Dim Calc As Integer
Dim p As Integer
Dim k As Integer
Dim n As Integer
Dim strVariable As Integer
Dim wa As Workbook
Dim twb As Workbook
Set twb = ThisWorkbook
Dim j As Integer
Range("A2", Range("A2").End(xlDown)).Select
Do
If ActiveCell.Value = "" Then Exit Do
ActiveCell.Offset(1, 0).Select
n = n + 1
Loop
p = 2
For k = 1 To n
ResimNo = InputBox("Please Enter Resim No")
Cells(p, 2).Value = ResimNo
strVariable = Left(ResimNo, 4)
Cells(p, 3).Value = strVariable
If strVariable = 5701 Then
Set wa = Workbooks.Open("C:\Users\userpc\Desktop\Gökhan\makro\Teknik Resim Arsiv Listesi_5701.xls")
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$H$1500"), , xlYes).Name = _
"Table1"
j = k + 1
With twb.Sheets("Sheet1")
.Cells(j, 4) = Application.VlookUp(.Cells(j, 2).Value2, "Table1", 6, False)
End With
End If
p = p + 1
Next k
End Sub
【问题讨论】:
-
我尝试时出现错误框:CompileError: Variablle is not Defined
-
我的错误
Application.VlookUp(.Cells(j, 2).Value2, wa.Sheets(1).Range("Table1"), 6, False)假设您的 Table1 列表对象位于wa工作簿的第一个工作表上 -
这次给了#N/A,我尝试了不同的工作簿,再次出现同样的错误,可能是关于我定义的表吗?
-
#N/A 表示该值未在表中找到
标签: vba excel vlookup inputbox