帮助,我似乎无法让这个vlookup工作。尝试将多个电子表格合并到第三个电子表格中。我在每个工作表中使用连接列作为引用和目标范围,然后在包含前两个列标题的第三个工作表上填充值。串联工作完美,第三个工作表上每个单元格中的数据总体是正确的,因为我用随机字符测试了这个,但是vlookup一直失败1004错误,当我坚持On Error Resume Next时,我什么都没得到。花了10个小时试图解决这个问题,所以任何帮助都将不胜感激。
'接下来准备每个工作表(MyT& E& MyShop)中的数据进行比较 '使用报告编号/发票ID,报销金额/金额,报销货币/货币,GL帐户/帐户
Dim theRange As String
Dim LastRow As Long
Dim Lastcol As Long
Dim Firstrow As Long
Dim Firstcol As Long
Sheets("MYSHOP").Select
LastrowMYSHOP = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
LastColMYSHOP = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
theRange = ("A3:" & "A" & LastrowMYSHOP)
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2").Select
ActiveCell.FormulaR1C1 = "Concatenate"
Range("A3").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(right(RC8,7),RC6,RC12,RC11)"
Selection.AutoFill Destination:=Range(theRange)
Range(theRange).Select
Columns("A:A").EntireColumn.AutoFit
Sheets("MYTE").Select
LastrowMYTE = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
LastcolMYTE = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
theRange = ("A2:" & "A" & LastrowMYTE)
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "Concatenate"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC5,RC15,RC18,RC19)"
Selection.AutoFill Destination:=Range(theRange)
Range(theRange).Select
Columns("A:A").EntireColumn.AutoFit
'接下来执行查找
Sheets("Consolidate").Select
Firstrow = 6
Firstcol = 26
LastrowConsolidate = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
LastcolConsolidate = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Dim ws1, ws2, ws3 As Worksheet
Dim TargetRange As Range
Dim RefRange As Range
Set ws1 = Sheets("MYTE")
Set ws2 = Sheets("MYSHOP")
Set ws3 = Sheets("Consolidate")
Set RefRange = ws1.Range("A2:" & "A" & LastrowMYTE)
Set TargetRange = ws2.Range("A3:" & "AD" & LastrowMYSHOP)
On Error Resume Next
LastColMYSHOP = LastColMYSHOP + 1 'Allow for the additional concatenation column
For i = 2 To LastColMYSHOP
For Each cl In RefRange
Result = Application.WorksheetFunction.VLookup(cl, TargetRange, i, False)
ws3.Cells(Firstrow, Firstcol).Value = Result
Firstrow = Firstrow + 1
Next cl
Firstrow = 6
Firstcol = Firstcol + 1
Next i