简体   繁体   English

VBA将粘贴列复制到其他工作表中

[英]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.

相关问题 使用 VBA 将列复制并粘贴到新工作表 - Using VBA to Copy and Paste Columns to New sheet VBA将工作表的某些列复制并粘贴到另一张工作表上的特定列 - VBA Copy and Paste Certain Columns of a sheet to specific columns on another sheet Excel VBA复制/粘贴列从多个工作表到不同列中的一个工作表 - Excel VBA copy/paste column from multiple sheets to one sheet in different Columns 复制工作表的最后一行并粘贴到另一工作表的VBA的最后一行 - Copy last row of a sheet and paste in last row of a different sheet VBA 从工作表复制范围,然后粘贴到不同列的另一工作表中 - Copy range from a sheet and paste into another sheet in different columns 有没有一种方法可以复制特定范围内的“浮动图片”,然后使用VBA将其粘贴到另一张纸上? - Is there a way to copy a “floating picture” in a specific range and paste it to different sheet with VBA? VBA复制并粘贴到另一个工作表 - VBA Copy and Paste to another sheet 如何在vba中复制和粘贴工作表? - How to copy and paste a sheet in vba? 每两列循环出现问题,使用不同工作表中的复制粘贴公式 - Problem with loop every 2 columns, with copy paste formula from different sheet VBA:循环从主表中复制某些列,创建新表并粘贴 - VBA: loop to copy certain columns from main sheet, create a new sheet, and paste
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM