|
楼主 |
发表于 2017-7-25 08:51
|
显示全部楼层
'把红色的Copy改为Cut,效率会慢10倍
Sub Finished()
t = Timer
Application.EnableEvents = False
UserForm1.Show 0 '有进度条,因此请下载附件后使用
DoEvents
With Sheet1
r = .Range("a" & Rows.Count).End(3).Row
If r < 3 Then Exit Sub
Set rng = .Range("s3:s" & r)
i = 0
For Each c In rng
If c = "Y" Or c = "y" Or c = "OK" Then
L = Sheet2.Range("a" & Rows.Count).End(3).Row
If L > Rows.Count - 2 Then Call NewSheet: L = Sheet2.Range("a" & Rows.Count).End(3).Row
c.EntireRow.Copy Sheet2.Range("a" & L + 1)
Application.CutCopyMode = False
c.EntireRow.ClearContents
i = i + 1
End If
UserForm1.Label1.Caption = "程序正在进行:" & Format(c.Row / (2 * r), "0.00%")
DoEvents
Next
Set rng = .Range("n3:n" & r)
For Each c In rng
If (c.Offset(, 1) <> "" And c.Offset(, 1) < Date) Or (c.Offset(, 1) = "" And c <> "" And c < Date) Then
L = Sheet2.Range("a" & Rows.Count).End(3).Row
If L > Rows.Count - 2 Then Call NewSheet: L = Sheet2.Range("a" & Rows.Count).End(3).Row
c.EntireRow.Copy Sheet2.Range("a" & L + 1)
Application.CutCopyMode = False
c.EntireRow.ClearContents
i = i + 1
End If
UserForm1.Label1.Caption = "程序正在进行:" & Format((c.Row + r) / (2 * r), "0.00%")
DoEvents
Next
.Range("3:" & r).Sort key1:=.Range("a3"), Order1:=xlAscending, header:=xlNo
r = .Range("a" & Rows.Count).End(3).Row
.Range(r & ":" & Rows.Count).Clear
.Range("a" & Rows.Count).End(3).Offset(1).Select
End With
Unload UserForm1
MsgBox "共移除 " & i & "项 已完成订单!用时" & Format(Timer - t, "0.00\秒") & vbCrLf & "按『确定』键结束"
Application.EnableEvents = True
Set rng = Nothing
End Sub
Sub NewSheet() '当备份工作表填满时,开启新工作表
Sheet2.Copy after:=Sheet2
ActiveSheet.Name = "备份_" & Format(Date, "yyyy-mm-dd")
Sheet2.Range("3:" & Rows.Count).Clear
End Sub
|
评分
-
1
查看全部评分
-
|