当两张工作表上的ID匹配时,从第二个电子表格(GL接口)复制2列数据。我逐步执行了该代码,并执行了捕获值并将其打印到目标的代码,但G2 a&H2中没有任何打印内容。有应该打印但不打印的值。每隔一行打印一次。
为什么第一次执行不打印值?实际上,这些值在第二次执行后确实出现过一次。
但是当我将目标列重置为空白并再次尝试时,第一次评估为true的值将不会显示在其目标列中。
为什么?
Sub Import_Data()
Dim lastRw1, lastRw2, nxtRw, m, lastColumn, rowCol
'Determine last row with data, Sheet1
lastRw1 = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'Determine last row with data, Import
lastRw2 = Sheets("GL Interfaces").Range("A" & Rows.Count).End(xlUp).Row
'Last Column
With ActiveSheet
lastColumn = .Range("A1").SpecialCells(xlCellTypeLastCell).Column
End With
MsgBox lastColumn '=> returns 36
'Heading
Range("A1:H1").HorizontalAlignment = xlCenter
Range("A1:H1").HorizontalAlignment = xlCenter
Range("A1:H1").Interior.Color = RGB(169, 208, 142)
Range("A1:H7172").Font.Color = RGB(0, 0, 0)
'Body
Range("A1:H7172").HorizontalAlignment = xlCenter
Range("A1:H7172").Font.Color = RGB(0, 0, 0)
'Loop through Sheet1, Column A
For nxtRw = 2 To lastRw2
'Search Sheet1 Column A for value from GL Interfaces
With Sheets("Sheet1").Range("A2:A" & lastRw1)
Set m = .Find(Sheets("GL Interfaces").Range("A" & nxtRw), LookIn:=xlValues, lookat:=xlWhole)
'Copy GL Interfaces row if match is found
If Not m Is Nothing Then
Sheets("GL Interfaces").Range("E" & nxtRw & ":F" & nxtRw).Copy _
Destination:=Sheets("Sheet1").Range("G" & m.Row)
End If
End With
Next
End Sub