简体   繁体   English

Mac 上 excel 中的进度条

[英]Progress bar in excel on a mac

I am using a progress bar in vba with excel but it will not display on my mac unless i step through, then it works fine.我在带有 excel 的 vba 中使用进度条,但除非我逐步完成,否则它不会显示在我的 mac 上,然后它工作正常。 Any suggestions?有什么建议?

Sub Delete_duplicates()

    Dim x As Integer
    Dim LastRow As Long
    Dim xMax As Long
    Dim MyTimer As Double

    LastRow = Range("A65536").End(xlUp).Row
    xMax = LastRow

    For x = LastRow To 1 Step -1
        Application.StatusBar = "Progress: " & x & " of  " & Format(xMax)
        If Application.WorksheetFunction.CountIf(Range("A3:A" & x), Range("A" & x).Text) > 1 Then
            Range("A" & x).EntireRow.Delete

        End If
    Next x
Application.StatusBar = False


End Sub

If you add DoEvents to your loop, the status bar will update.如果将DoEvents添加到循环中,状态栏将更新。 Something like this:像这样的东西:

   For x = LastRow To 1 Step -1
        Application.StatusBar = "Progress: " & x & " of  " & Format(xMax)
        DoEvents ' <<<<<<< new line
        If Application.WorksheetFunction.CountIf(Range("A3:A" & x), Range("A" & x).Text) > 1 Then
            Range("A" & x).EntireRow.Delete  
        End If
    Next x

You might consider not doing this on every row - for example you could have a line您可能会考虑不在每一行都这样做 - 例如,您可以有一条线

If Mod(x, 10) = 0 Then DoEvents

to make the updating less frequent.以减少更新频率。 Experiment a bit until you get the result you want.试验一下,直到你得到你想要的结果。

Source: http://www.ozgrid.com/forum/showthread.php?t=160203来源: http : //www.ozgrid.com/forum/showthread.php? t= 160203

I don't have the reputation points yet to make the comment, but I thought I should point out that @Floris' suggestion:我还没有发表评论的声誉点,但我想我应该指出@Floris 的建议:

    If Mod(x, 10) = 0 Then DoEvents

only works as a worksheet function.仅用作工作表函数。 In order to use Mod in VBA, you need to use the following syntax:为了在 VBA 中使用 Mod,您需要使用以下语法:

    If x Mod 10 = 0 Then DoEvents

At least, that's how it needs to work on Excel for Mac 2011, on my computer.至少,这就是它需要在我的计算机上的 Excel for Mac 2011 上工作的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM