简体   繁体   English

满足条件时将各种单元格复制并粘贴到另一个工作表

[英]Copy and Paste various cells to another sheet when condition met

I need a little help because I´m trying to Copy and Paste selected cells from the same row to another sheet when condition are met, but I'm kind of lost, I hope you can help me我需要一点帮助,因为我正在尝试在满足条件时将选定的单元格从同一行复制并粘贴到另一张纸上,但我有点迷茫,希望你能帮助我

for example, I have the datasheet called sheet7 that contain data range(A4 to AF40) and my condition is that can copy and paste all rows that met Column E = "Contract" but to be able to copy some other cells, for example, columns D, G, O, and V例如,我有一个名为 sheet7 的数据表,其中包含数据范围(A4 到 AF40),我的条件是可以复制和粘贴所有符合 Column E =“Contract”但能够复制其他一些单元格的行,例如, D、G、O 和 V 列

I want to pass all that data to a new sheet called sheet10我想将所有这些数据传递给一个名为 sheet10 的新工作表

I hope it has been clear, and I hope you can help me我希望它已经清楚了,我希望你能帮助我

Private Sub CommandButton2_Click()
    
    Dim range1 As Range
    Dim Cell As Range
    
    Set range1 = Sheet1.Range("E4:E100")

    For Each Cell In range1
        If Cell.Value = "Contract" Then
            With Sheet7
                .Range(.Cells(Cell.Row, "C"), .Cells(Cell.Row, "F")).Copy _
                    Sheet10.Range("B100").End(xlUp).Offset(1, 0)
            End With
        End If
    Next

End Sub

Copy Intersecting Rows and Columns复制相交的行和列

Option Explicit

Private Sub CommandButton2_Click()

    ' Lookup Range
    Dim llRow As Long
    Set llRow = Sheet1.Range("E" & Sheet1.Rows.Count).End(xlUp).Row
    Dim lrg As Range: Set lrg = Sheet1.Range("E4:E" & llRow)
    
    ' Source Columns Range
    Dim scrg As Range
    With Sheet7
        Set scrg = Union(.Columns("D"), .Columns("G"), _
            .Columns("O"), Columns("V"))
    End With
    
    ' Destination Cell
    Dim dfCell As Range
    Set dfCell = Sheet10.Range("B" & Sheet10.Rows.Count).End(xlUp).Offset(1, 0)
    
    Dim srg As Range ' Source Range
    Dim lCell As Range ' Lookup Cell

    For Each lCell In lrg.Cells
        If StrComp(CStr(lCell.Value), "Contract", vbTextCompare) = 0 Then
            ' Combine cell into a range.
            If srg Is Nothing Then
                Set srg = Sheet7.Cells(lCell.Row, "A")
            Else
                Set srg = Union(srg, Sheet7.Cells(lCell.Row, "A"))
            End If
        End If
    Next lCell
    
    If srg Is Nothing Then Exit Sub
    
    Set srg = Intersect(srg.EntireRow, scrg)
    
    srg.Copy dfCell

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 满足条件时,将仅行的一部分复制粘贴到另一张纸上,其中一个单元格包含图片 - Copy paste only part of rows, with one cell containing a picture, on another sheet when condition is met 满足条件时,Excel VBA 从一张纸到另一张纸的复制粘贴循环 - Excel VBA copy paste loop from one sheet to another when condition is met 动态满足条件时将数据从一张表复制到另一张表 - Copy data from one sheet to another when condition is met dynamically 如果条件满足,我如何使用 VBA 代码复制和粘贴特定单元格到另一个工作表的不同区域 - How can i use VBA Code to Copy and Paste Specific Cells if Condition is Met to different areas of another worksheet 在满足条件的情况下将单元格复制到另一个工作表 - Copy Cell to another sheet in condition is met Loop 如果满足条件,则将单元格复制到另一张工作表 - Copy cell to another sheet if condition is met 如果满足特定条件,如何从另一张纸的每一行中复制特定单元格? - How to copy specific cells from each row in another sheet if certain condition is met? 如果条件满足,则用于复制和粘贴特定单元格的 VBA 代码 - VBA Code to Copy and Paste Specific Cells if Condition is Met VBA 代码复制粘贴多个单元格,如果条件满足 - VBA Code Copy Paste Multiple Cells if Condition is Met 满足条件时,VBA复制单元 - VBA to Copy Cells When Condition Is Met
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM