Excel: 如果某个单元格不为空,则将行复制到另一个工作表

Excel: Copy a row to another worksheet if a certain cell is not empty

我希望使用能够在所述 sheet 中搜索列的宏,如果单元格不为空(单元格 T),它会复制整行 data/formatting并将其粘贴到另一个 sheet [sheet "genealogie" in my case] 以及包含非空单元格的任何其他行。

https://i.stack.imgur.com/ISRcD.png

我试过这段代码,但不幸的是,即使相关单元格(T 列)为空,它也会复制所有行。

Sub Copyl()
Dim Cell As Range
With Sheets("Tableur")

    For Each Cell In .Range("B7:B" & .Cells(.Rows.Count, "B").End(xlUp).Row)
        If Not IsEmpty(Range("T7:T" & .Cells(.Rows.Count, "T").End(xlUp).Row).Value) Then

            .Rows(Cell.Row).Copy Destination:=Sheets("genealogie").Rows(Cell.Row)

        End If
    Next Cell

End With
End Sub

提前致谢....

  1. 确定您的输入范围
  2. 在该范围内设置自动过滤器Field:=19, Criteria1:="<>", Operator:=xlFilterValues(假设您的数据从 Colmunb 开始)-“<>”选择非空白,需要 Operator 参数来指定过滤操作的类型[​​=20=]
  3. input_range.SpecialCells(xlCellTypeVisible).copy destination_range
  4. input_range.AutoFilter 删除自动过滤

你检查T列中的整个范围:只检查相应行中的单个单元格

Sub Copyl()
    Dim Cell As Range
    With Sheets("Tableur")

    For Each Cell In .Range("B7:B" & .Cells(.Rows.Count, "B").End(xlUp).Row)
    '--> check the value in T column in the corresponding row
        If Not IsEmpty(.Cells(Cell.Row, "T")) Then

            .Rows(Cell.Row).Copy Destination:=Sheets("genealogie").Rows(Cell.Row)

        End If
    Next Cell
    End With
End Sub