【发布时间】:2018-09-24 14:53:40
【问题描述】:
下面的 VBA 代码表示一个复制粘贴函数,由两个条件过滤。代码可以工作并完成工作,但问题是它生成结果的时间 - 这里有没有人知道编写相同代码的更有效方法? 任何建议都非常感谢
Private Sub CommandButton3_Click()
Dim c As Range, i As Integer, j As Integer
Range("N6:R50").ClearContents
i = 0
For Each c In Range("B2:B50")
If c = Range("O3").Value And Month(c.Offset(0, -1).Value) = Range("P1").Value Then
Cells(6 + i, 14) = Cells(c.Row, c.Column - 1)
Cells(6 + i, 15) = Cells(c.Row, c.Column + 1)
Cells(6 + i, 16) = Cells(c.Row, c.Column + 2)
Cells(6 + i, 17) = Cells(c.Row, c.Column + 3)
Cells(6 + i, 18) = Cells(c.Row, c.Column + 4)
End If
i = i + 1
Next c
For j = 50 To 6 Step -1
If Cells(j, 15) = "" Then
Range("N" & j, "R" & j).Delete Shift:=xlUp
End If
Next j
End Sub
【问题讨论】:
-
你能分享一个你拥有的数据集的例子吗?可能的解决方案可能是对列 A 和 B 应用过滤器,然后复制过滤行的值(而不是循环)。
标签: vba excel filter copy-paste