VBA在不同的工作表中复制粘贴列

我有两张表 – 延迟,TP。 只有当“Latency”col E有string“COMPATIBLE”,col O有string“Pass”时,我需要从“Latency”复制col M并粘贴到“TP”的col D中。

我有下面的代码,但它不给任何结果。

我不确定它有什么问题:

Sub sbMoveData() Dim lRow As Integer, i As Integer, j As Integer 'Find last roe in Sheet1 With Worksheets("Latency") lRow = .Cells.SpecialCells(xlLastCell).Row j = 1 For i = 1 To lRow If UCase(.Range("E" & i)) = "COMPATIBLE" And UCase(.Range("O" & i)) = "Pass" Then .Range("M" & i).Copy Destination:=Worksheets("TP").Range("D" & j) j = j + 1 End If Next End With 

结束小组

尝试这个

 Sub sbMoveData() Dim lRow As Integer, i As Integer, j As Integer Dim ws1, ws2 As Worksheet Set ws1 = ThisWorkbook.Sheets("Latency") Set ws2 = ThisWorkbook.Sheets("TP") 'Find last roe in Sheet1 lRow = ws1.Cells.SpecialCells(xlLastCell).Row j = 1 For i = 1 To lRow If ws1.Range("A" & i) = "COMPATIBLE" And ws1.Range("B" & i) = "Pass" Then ws1.Range("M" & i).Copy Destination:=ws2.Range("D" & j) j = j + 1 End If Next i End Sub 

UCase(.Range(“O”&i))=“Pass”将永远是错误的:-)

你永远不会匹配UCase(Cell)=“Pass”,对吗? 你或者需要有:

 UCase(.Range("O" & i)) = "PASS" 

要么

 .Range("O" & i) = "Pass"