How can I display a progress bar for a built-in Ex

2019-07-31 14:08发布

I have an Excel table set up with around 40,000 values that need to be sorted via a userform. For this, I used...

myTable.Sort.SortFields.Add Range(strSortBy), xlSortOnValues, xlDescending, xlSortNormal
myTable.Sort.Apply

...where myTable is the table and strSortBy is the header of the column I want to sort by.

Now, despite Excel's lightning-fast sorting capabilities, with this amount of data it starts taking long enough (several seconds) that I'd like to provide the user with some kind of progress feedback. I've made several userform progress-bars in Excel, but since Sort is a built-in Excel function, I can't see any obvious ways to show or determine the percentage completed.

Is this a lost cause? Or is there some way to determine the progress of built-in functions?

Any help is greatly appreciated.

1条回答
迷人小祖宗
2楼-- · 2019-07-31 14:11

I like to use the status bar function, which is built in, to display progress. It is very simple, yet powerful.

Example:

Application.StatusBar = "Renaming Cells"

While count2 <= (count1)
    DoEvents
    Length = Len(Range("C" & CStr(count2)).Value)
    Newlength = Length - 2
    newID = Left(Range("C" & CStr(count2)).Value, Newlength)
    Range("C" & CStr(count2)).Value = newID
    count2 = count2 + 1
    newID = vbNullString
    Application.StatusBar = "Editing Cell: " & count2 & " of " & count1 & "."
Wend

In the example, I'm able to loop through cells, shortening the length of each one. While doing so, I display the cell the program is on, since it can take a long time.

Hope this helps!

查看更多
登录 后发表回答