VBA将粘贴列复制到其他工作表中 [英] VBA Copy paste columns in different sheet

查看:102
本文介绍了VBA将粘贴列复制到其他工作表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张纸-Latency,TP.我只需要从等待时间"复制col M并将其粘贴到"TP"的col D中,只有当等待时间" col E的字符串为"COMPATIBLE",而col O的字符串为"Pass"时,才需要将其粘贴到"TP"的col D中.

I have two sheets – 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".

我有以下代码,但没有任何结果.

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

结束子

推荐答案

尝试一下

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

这篇关于VBA将粘贴列复制到其他工作表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆