[英]My VBA Vlookup is returning N/A. What am I doing wrong?
So I have a list that was pre-assembled and I'm attempting to now add more to the list from another workbook I have.所以我有一个预先组装的列表,我现在正试图从我拥有的另一个工作簿中添加更多到列表中。 I figured I could use VBA to create a macro to perform a VLookup to retrieve and populate the added fields.
我想我可以使用 VBA 创建一个宏来执行 VLookup 来检索和填充添加的字段。
My VBA:我的 VBA:
Option Explicit
Sub CompareUntimed()
Dim wb As Workbook
Dim utsheet As Worksheet
Dim utlastrow, f9lastrow, J As Long
Dim f9sheet As Worksheet
Dim ctr As Integer
Set wb = Workbooks.Open(get_user_specified_filepath())
Set utsheet = wb.Sheets(2)
utlastrow = utsheet.Cells(Rows.Count, "A").End(xlUp).Row
Set f9sheet = ThisWorkbook.Sheets("Part List")
f9lastrow = f9sheet.Cells(Rows.Count, "A").End(xlUp).Row
For J = 2 To f9lastrow
f9sheet.Range("G" & J) = Application.VLookup(f9sheet.Range("H" & f9lastrow), utsheet.Range("S2:S" & utlastrow), 17, False)
f9sheet.Range("F" & J) = Application.VLookup(f9sheet.Range("H" & f9lastrow), utsheet.Range("S2:S" & utlastow), 10, False)
Next J
End Sub
This is the Workbook where I'm getting #N/A instead of the proper values这是我得到#N/A 而不是正确值的工作簿
This is the Workbook I'm attempting to match to and take values from这是我试图匹配并从中获取值的工作簿
I'm attempting to use the UniqueID columns I've created which is the last column in each workbook and I'm attempting to add the dates and modified by columns to my new workbook.我正在尝试使用我创建的 UniqueID 列,这是每个工作簿中的最后一列,并且我正在尝试将日期和按列修改的列添加到我的新工作簿中。
Sub CompareUntimed()
Dim wb As Workbook
Dim utsheet As Worksheet
Dim utlastrow, f9lastrow, J As Long
Dim f9sheet As Worksheet
Dim ctr As Long
Set wb = Workbooks.Open(get_user_specified_filepath())
Set utsheet = wb.Sheets(2)
Set f9sheet = ThisWorkbook.Sheets("Part List")
f9lastrow = f9sheet.Cells(Rows.Count, "A").End(xlUp).Row
For J = 2 To f9lastrow
m = Application.Match(f9sheet.Range("H" & J), utsheet.Columns("S"), 0)
If Not IsError(m) Then
f9sheet.Range("G" & J).Value = utsheet.Cells(m, "K").Value
f9sheet.Range("F" & J).Value = utsheet.Cells(m, "R").Value
Else
f9sheet.Range("F" & J).Resize(1,2).Value = "???"
End If
Next J
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.