Skip i'r prif gynnwys

Sut i greu stopwats yn nhaflen waith Excel?

Os oes stopwats yn eich taflen waith, byddwch chi'n gwybod yr amser i orffen swydd. Sut allwch chi greu stopwats mewn dalen gyda Botwm Cychwyn, Stopio ac Ailosod fel y dangosir y screenshot canlynol? Os cliciwch y botwm Start, bydd yn amser cychwyn, os cliciwch ar Stop botwm, bydd yn stopio amser, a gall y botwm Ailosod eich helpu i ailosod amser. Yr erthygl hon, byddaf yn siarad am sut i greu stopwats syml a defnyddiol yn Excel.

doc creu stopwats 1

Creu stopwats gyda thri botwm trwy ddefnyddio cod VBA


Creu stopwats gyda thri botwm trwy ddefnyddio cod VBA

I greu stopwats gyda thri botwm, Cychwyn, Stopio ac Ailosod, gwnewch y camau canlynol fesul un.

Yn gyntaf, mewnosodwch dri botwm gorchymyn.

1. Cliciwch Datblygwr > Mewnosod > Botwm Gorchymyn, gweler y screenshot:

doc creu stopwats 2

2. Yna llusgwch y llygoden i dynnu botwm, ar ôl mewnosod y botwm, gallwch newid pennawd y botwm, cliciwch Datblygwr > Eiddo, Yn y Eiddo deialog, nodwch y pennawd newydd “dechrau”Ar gyfer y botwm hwn yn y blwch testun wrth ymyl y Geiriad, gweler sgrinluniau:

doc creu stopwats 3 2 doc creu stopwats 4

3. Ailadroddwch y ddau gam uchod i fewnosod dau fotwm arall a'u rhoi mewn pennawd fel “Stop"A"Ailosod”, Gweler y screenshot:

doc creu stopwats 5

4. Ar ôl mewnosod y botymau, dylech adael y modd dylunio trwy glicio Datblygwr > Modd Dylunio.

Yn ail, creu cod VBA.

5. Ac yna, cliciwch ar y dde ar y tab taflen waith gyfredol, a dewiswch Gweld y Cod, yn y popped allan Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, copïwch a gludwch y cod canlynol i'r Cod Taflen:

Cod VBA: Creu stopwats:

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 creu stopwats 6

Nodyn: Yn y cod uchod, C2 yw'r gell lle bydd yr amser stopwats yn cael ei fewnosod, a'r Botwm Gorchymyn1, Botwm Gorchymyn2, Botwm Gorchymyn3 yw'r enwau botwm, gallwch weld union enw'r botwm o'r Blwch Enw, gweler y screenshot:

doc creu stopwats 7

Yn drydydd, fformatiwch y gell amser stopwats.

6. Yna dylech fformatio'r gell amser fel Testun fformat, a gallwch newid maint y gell, ffont, lliw ffont, cefndir, ac ati yn ôl yr angen, gweler y screenshot:

doc creu stopwats 8

7. Ar ôl gorffen uwchben y camau, o hyn ymlaen, pan gliciwch dechrau botwm, bydd yr amser yn dechrau nawr, a chlicio Stop botwm, bydd yn stopio amser, y Ailosod botwm yn ailosod yr amser, gweler y screenshot:

doc creu stopwats 9


Demo: Creu stopwats gyda thri botwm trwy ddefnyddio cod VBA

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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