[英]VBA Copy paste columns in different sheet
I have two sheets – Latency, TP. 我有两张纸-Latency,TP。 I need to copy col M from "Latency" and paste it into col D of "TP" only if "Latency" col E has the string “COMPATIBLE” and col O has the string “Pass”.
我只需要从“等待时间”复制col M并将其粘贴到“ TP”的col D中,只有当“等待时间” col E具有字符串“ COMPATIBLE”并且col O具有字符串“ Pass”时。
I have the below code, but it doesn't give any result. 我有以下代码,但没有任何结果。
I'm not sure whats wrong with it: 我不确定这是怎么回事:
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
End Sub 结束子
UCase(.Range(“ O”&i))=“ Pass”将始终为假:-)
You are never going to match UCase(Cell) = "Pass", right? 您永远都不会匹配UCase(Cell)=“ Pass”,对吗? You either need to have:
您要么需要具备以下条件:
UCase(.Range("O" & i)) = "PASS"
or 要么
.Range("O" & i) = "Pass"
Try this 尝试这个
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.