Ga naar hoofdinhoud

Hoe maak je een stopwatch in Excel-werkblad?

Als er een stopwatch op uw werkblad staat, weet u hoe laat het is om een ​​klus te klaren. Hoe kun je een stopwatch maken in een blad met een Start-, Stop- en Reset-knop zoals in het volgende screenshot wordt getoond? Als u op de Start-knop klikt, wordt de tijd gestart, als u op de knop Stop klikt, wordt de tijd gestopt en met de knop Reset kunt u de tijd opnieuw instellen. In dit artikel zal ik het hebben over het maken van een eenvoudige en handige stopwatch in Excel.

doc stopwatch maken 1

Maak een stopwatch met drie knoppen met behulp van VBA-code


Maak een stopwatch met drie knoppen met behulp van VBA-code

Om een ​​stopwatch te maken met drie knoppen, Start, Stop en Reset, voert u de volgende stappen een voor een uit.

Voeg eerst drie opdrachtknoppen in.

1. Klikken Ontwikkelaar > Invoegen > Command knop, zie screenshot:

doc stopwatch maken 2

2. Sleep vervolgens met de muis om een ​​knop te tekenen, na het invoegen van de knop kunt u het bijschrift van de knop wijzigen, klik alstublieft Ontwikkelaar > Properties, in de Properties dialoogvenster, voer het nieuwe bijschrift in "Start”Voor deze knop in het tekstvak naast de Onderschrift, zie screenshots:

doc stopwatch maken 3 2 doc stopwatch maken 4

3. Herhaal de bovenstaande twee stappen om nog twee knoppen in te voegen en ze te onderschrijven als 'stop"En"Reset”, Zie screenshot:

doc stopwatch maken 5

4. Nadat u de knoppen heeft ingevoegd, verlaat u de ontwerpmodus door op te klikken Ontwikkelaar > Ontwerpmodus.

Maak ten tweede een VBA-code.

5. En klik vervolgens met de rechtermuisknop op het huidige werkbladtabblad en kies Bekijk code, in de pop uit Microsoft Visual Basic voor toepassingen -venster, kopieer en plak de volgende code in het Bladcode:

VBA-code: stopwatch maken:

Public StopIt As Boolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("C2") = 0 Then
  StartTime = Timer
  PauseTime = 0
  LastTime = 0
Else
  StartTime = 0
  PauseTime = Timer
End If
StartIt:
  DoEvents
  If StopIt = True Then
    LastTime = TotalTime
    Exit Sub
  Else
    FinishTime = Timer
    TotalTime = FinishTime - StartTime + LastTime - PauseTime
    TTime = TotalTime * 100
    HM = TTime Mod 100
    TTime = TTime \ 100
    hh = TTime \ 3600
    TTime = TTime Mod 3600
    MM = TTime \ 60
    SS = TTime Mod 60
    Range("C2").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
    If ResetIt = True Then
      Range("C2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
      LastTime = 0
      PauseTime = 0
      End
    End If
    GoTo StartIt
  End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  StopIt = True
End Sub
Private Sub CommandButton3_Click()
  Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
  LastTime = 0
  ResetIt = True
End Sub

doc stopwatch maken 6

Note: In de bovenstaande code, C2 is de cel waar de stopwatchtijd zal worden ingevoegd, en de CommandoKnop1, CommandoKnop2, CommandoKnop3 zijn de knopnamen, u kunt de exacte knopnaam zien in de Naam Box, zie screenshot:

doc stopwatch maken 7

Ten derde, formatteer de stopwatch-tijdcel.

6. Vervolgens moet u de tijdcel opmaken als Tekst formaat, en u kunt de celgrootte, het lettertype, de lettertypekleur, de achtergrond, enz. naar behoefte wijzigen, zie screenshot:

doc stopwatch maken 8

7. Na het voltooien van bovenstaande stappen, vanaf nu, wanneer u op klikt Start knop, de tijd zal nu beginnen, en klik stop knop, zal het de tijd stoppen, de Reset knop reset de tijd, zie screenshot:

doc stopwatch maken 9


Demo: maak een stopwatch met drie knoppen met behulp van VBA-code

Beste Office-productiviteitstools

🤖 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar efficiëntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
Comments (32)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
One has to paste the VBA code to the Sheet's VBA space, not to the Module!

=> I suggest correcting, in the article, the "copy and paste the following code into the Module" -> replace Module with Sheet's VBA field, or sth

Otherwise, perfect, thanks!
This comment was minimized by the moderator on the site
Hello, Florian,

Thanks for your comment, we have updated the content for this article.
Thanks again! 😀
This comment was minimized by the moderator on the site
i started. it works. but it doesn't work when i close and open the excel file again. what must i do?
This comment was minimized by the moderator on the site
Hello, mustafa zirek
After inputing the code, you should save the workbook as Excel Macro-Enabled Workbook format, and when you open the workbook next time, please click the Enable Content above the formula bar to activate the code.
Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi! Thank you for this, how do I make it so it populates time in subsequent cells, ex. start/stop time for cell C2, then a different start/stop time for cell c3, c4, c5 etc 
This comment was minimized by the moderator on the site
Bonjour, j'ai voulu intégrer ce chronomètre à une autre macro, déterminer le temps d'utilisation du fichier. La macro se lance mais bloque l'utilisation du fichier.Comment faire pour utiliser votre chronomètre en même temps que d'autres codes VBA?MerciHenry.
This comment was minimized by the moderator on the site
Is it possible to use a combobox or a dropdown selection to start and stop the clock
This comment was minimized by the moderator on the site
This is brilliant! Thanks, Chris H
This comment was minimized by the moderator on the site
Hello
Have followed the steps but cannot get a time to appear in the timer cell. I have copied the code but can i check1. That the line numbers are not needed or are they2. That I put the code into module 1 not sheet1 or This workbook3. Should there be a macro listed in the macro list after doing all this - mine doesn't.
Thanks
This comment was minimized by the moderator on the site
Hi, Janice,You should put the code into your active sheet module as step 5.
5. And then, right click the current worksheet tab, and choose View Code, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the Module.

And you should change the button name to your own.
Note: In the above code, C2 is the cell where the stopwatch time will be inserted, and the CommandButton1, CommandButton2, CommandButton3 are the button names, you can view the exact button name from the Name Box.

Please check them, thank you!
This comment was minimized by the moderator on the site
Is it possible to get the counter to count only seconds?
So when it reaches 59 seconds, it continues with 60, 61, 62, 63 ....
This comment was minimized by the moderator on the site
is 'timer' a variable here? dont see its relevance in the code.
This comment was minimized by the moderator on the site
How about adding "+10s" & "2x Speed" feature in this code?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations