在VBA中如何编写复制代码?
在EXECL VBA中,如何把Sheet1符合条件的行复制到Sheet2中?如数量小于是 0的行。
[解决办法]
比如Sheet1中有A与B两列,第一列为数量,将数量小于0的行复制到Sheet2中:
Sub test() Dim wks1 As Worksheet, wks2 As Worksheet Dim finalrow As Long Dim i As Long, j As Long Set wks1 = Worksheets("sheet1") Set wks2 = Worksheets("sheet2") finalrow = wks1.Cells(wks1.Rows.Count, 1).End(xlUp).Row For i = 2 To finalrow If wks1.Cells(i, 1).Value < 0 Then wks1.Cells(i, 1).Resize(1, 2).Copy wks2.Cells(j + 1, 1) j = j + 1 End If Next iEnd Sub