复制&范围符合标准时粘贴

时间:2016-11-09 14:16:58

标签: vba excel-vba copy-paste excel

我只是想知道是否有人知道如何修改下面的代码,以便它只复制D列中的值超过0的行

    Sub ADDTOORDERS()
Dim Sh As Worksheet, C As Worksheet, Last As Long
Set Sh = Sheets("Menu")
Set C = Sheets("LensOrder")
With Sh
Last = .Cells(Rows.Count, 2).End(xlUp).Row
    .Range("B7:D" & Last).AutoFilter Field:=2, Criteria1:=">0", Operator:=xlAnd
    .Range("B7:D" & Last).SpecialCells(xlCellTypeVisible).Copy
    C.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
    Sheets("Menu").Range("C3").Select
   .Range("B7:D" & Last).AutoFilter
End With
End Sub

1 个答案:

答案 0 :(得分:1)

dim i as Long

for i = 7 to 68 
    If Sheets("Menu").Range("D" & i).Value > 0 Then
        Sheets("Menu").Range("B" & i & ":D" & i).Copy
        Sheets("LensOrder").Range("A" & Rows.Count).End(xlUp).Offset(1,0).PasteSpecial (xlPasteValues)
    End If 
Next i