根据单元格中的数量复制VBA中的粘贴

  • 本文关键字:VBA 复制 单元格 vba excel
  • 更新时间 :
  • 英文 :


是否可以将vba代码检查列B,e,e,h,k,n从Sheep1的数字大于0,然后复制并粘贴该单元格,一个之前和一个单元格在A,b和c?

列中的Sheep2之后的一个之后

这是我一直在使用的代码,但它正在使用整个行,这并不是我想要的,因为它提供了很多不必要的内容:

Sub Epicerie()
For Each Cell In Sheets("Liste").Range("B:B, E:E, H:H, K:K, N:N")
    If Cell.Value > 0 Then
        matchRow = Cell.Row
        Rows(matchRow & ":" & matchRow).Select
        Selection.Copy
        Sheets("Listepret").Select
        ActiveSheet.Rows(matchRow).Select
        ActiveSheet.Paste
        Sheets("Liste").Select
    End If
Next
End Sub

我认为您是按照下面的代码之类的东西:

Option Explicit
Sub Epicerie()
Dim Cell As Range
For Each Cell In Sheets("Liste").Range("B:B, E:E, H:H, K:K, N:N")
    If Cell.Value > 0 Then
        With Sheets("Listepret")
            ' copy paste in 1 line to the next empty row at Column "A"
            Cell.Offset(, -1).Resize(1, 3).Copy Destination:=.Range("A" & .Cells(.Rows.Count, "A").End(xlUp).Row + 1)
        End With
    End If
Next
End Sub

最新更新