vba excel loop_在运行时显示迭代次数(不是进度条)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24870984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vba excel loop_ show iteration number while running (not progress bar)
提问by GabyLP
I have 250.000 lines and I wanted to erase all lines that have a 0 in col AR. This takes too much time using a filter and deleting only visible cells, so I wrote a code. The thing is that I would like to see the progress, but not adding a form, only the number of iteration would be enough.
我有 250.000 行,我想擦除所有在 col AR 中为 0 的行。这需要太多时间使用过滤器并仅删除可见单元格,所以我写了一段代码。问题是我想看到进度,但不添加表单,只有迭代次数就足够了。
Is there a way to show the iteration number while running the loop?
有没有办法在运行循环时显示迭代次数?
My code is:
我的代码是:
Sub delrow()
Application.Calculation=xlCalculationManual
Application.ScreenUpdating = False
With Sheets("bners")
LR3 = Range("A" & Rows.Count).End(xlUp).Row
For i3 = 3 To LR3
a = Sheets("bners").Range("AR" & i3).Value
If a = 0 Then
Rows(i3).Delete
Else
End If
Next i3
End With
Application.calculate
Application.ScreenUpdating = True
End Sub
Thanks!
谢谢!
回答by Alex
Use StatusBar and it will shown on the Statusbar (Duh):
使用状态栏,它将显示在状态栏上(废话):
Application.StatusBar = "Current iteration: " & i3
回答by mrbungle
I like to use
我喜欢用
count = 0
For....
'your code
count = count + 1
Application.StatusBar = Count
next
Displays at the bottom status bar. Simple and to me does not weigh heavy.
显示在底部状态栏。简单,对我来说并不重。
回答by SmarterThanYogi
You could add this inside your loop:
您可以将其添加到循环中:
Range("A1") = i3
This would set the top left cell to the number to the current iteration, though it wont be very smooth.
这会将左上角单元格设置为当前迭代的数字,尽管它不会很平滑。