此子项获取先前细分的数据(新书),并应搜索第二个工作簿(Previous_Data)以在第一列中找到与新书中的列51相匹配的值的行。从这里,我打算将接下来的8列复制到newbook的底部(尚未测试该部分)。我在这里遇到错误,并且显式使用了选项,但是它不允许我进入此子程序,并且无法重做整个程序。
Sub lastitem(newbook)
Dim lw As Long
Dim m As Range
Dim raw As Range
Dim rngPrevious As Range
Dim thirdwb As Workbook
Item = newbook.Sheets("Sheet1").Cells(2, 51).Value
MsgBox ("Here")
Set rngPrevious = Workbooks.Open("C:\Users\me\Desktop\Programing with
extra itd step\Previous_Data").Sheets("Data") _
.Range("A1:I500") 'adjust to suit
Set thirdwb = Workbook.Previous_Data.xlsm
MsgBox ("Here")
'm = Application.Match(Item, rngPrevious, 0) (old attempt, cant get to
work)
myrow = 2
For Each r In Intersect(thirdwb.Sheets("Data").Range("a:a"),
thirdwb.Sheets("Data").UsedRange)
If r = Item Then
MsgBox (r)
End If
myrow = myrow + 1
Next r
'Set raw = rngPrevious.Rows(m) 'get a reference to the matched row
'MsgBox ("Here set")
'lastRow = newbook.Sheets("Sheet1").UsedRange.Rows.Count
'MsgBox (lastRow)
'If newbook.Sheets("Sheet1").Range("a2") <> "" Then
'lw = newbook.Sheets("Sheet1").Range("a2").End(xlDown).Row
'If lw = "1048576" Then
'lw = "2"
'End If
'newbook.Sheets("Sheet1").Cells(lw + 2, 15).Print raw.Cells(2)
'End If
rngPrevious.Close
End Sub
错误如标题中所述。注释掉的部分要么是我尚未测试的未来元素,要么是我尝试过的替代