Simple TImer / Clock on Userform VBA

pmich

Active Member
Joined
Jun 25, 2013
Messages
289
I need a Simple Timer on Userform which uses Excel files through VBA.


After getting User's choice, say the text "Ben", which is a portion of a name, my code collects data of all records having "Ben" from the Excel file, which has about 5000 records (still growing) and displays the resulting data of the selected records in Listview control. It is a lengthy code.


If a particular search has more records to display, then displaying them on listview control takes more time. So, I am using a progress bar to tell the user that work is being done.


Is it possible to run a timer to display something like a digital clock to show the user the elapsed time. In addition to the progress bar, the user will also see the running clock (or timer) and wait until all chosen records are displayed.


I could not find a similar one on the net. Please help. Thanks in advance.
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

BrianMH

Well-known Member
Joined
Mar 26, 2008
Messages
1,490
Add a textbox and in the same code as your progress bar when updates the progress bar have it update the time elapsed in the textbox. You need a variable for the start time and then to get the elapsed to starttime-now().
 

pmich

Active Member
Joined
Jun 25, 2013
Messages
289
I just wanted to post my code here. Instead of TextBox I am using LABEL. I altered the code to show the actual time took for displaying data.
Code:
Dim Timecountr As Integer
Dim MinuteCntr As Integer
Timecountr = Timecountr + 1
     If Timecountr > 60 Then
      MinuteCntr = Int(Timecountr / 60)
      lblMinuteSecondCntr.Caption = Trim(Str(MinuteCntr)) & " Min. " & Trim(Str(Timecountr - (60 * MinuteCntr))) & " Sec."
     Else
      lblMinuteSecondCntr.Caption = Trim(Str(MinuteCntr)) & " Min. " & Trim(Str(Timecountr)) & " Sec."
     End If
I am still learning. Appreciate your guidance. I could not locate SOLVED button in this forum. So I just clicked LIKE Button.
 
Last edited:

pmich

Active Member
Joined
Jun 25, 2013
Messages
289
Based on your suggestion I could come up with this code and it works:
Code:
   Dim strStartTime As String
   Dim strEndTime As String
   Dim dtSeconds As Long
   Dim Roller As Long
   strStartTime = Now()
   For Roller = 1 To 5000000
   Next
   strEndTime = Now()
   dtSeconds = DateDiff("s", CDate(strStartTime), CDate(strEndTime)) 'got this from NET.
   MsgBox dtSeconds & " Sec."
Thanks for guiding me.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,122
Messages
5,599,830
Members
414,341
Latest member
Mohammedsobhey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top