简体   繁体   中英

How can I display a progress bar for a built-in Excel function?

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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