メインコンテンツへスキップ

Excelワークシートでストップウォッチを作成するにはどうすればよいですか?

ワークシートにストップウォッチがある場合は、ジョブを終了する時間がわかります。 次のスクリーンショットに示すように、開始、停止、リセットボタンを使用してシートにストップウォッチを作成するにはどうすればよいですか? [開始]ボタンをクリックすると開始時刻になり、[停止]ボタンをクリックすると停止時刻になります。[リセット]ボタンを使用すると、時刻をリセットできます。 この記事では、Excelでシンプルで便利なストップウォッチを作成する方法について説明します。

doc create ストップウォッチ 1

VBAコードを使用して、XNUMXつのボタンでストップウォッチを作成します


VBAコードを使用して、XNUMXつのボタンでストップウォッチを作成します

スタート、ストップ、リセットのXNUMXつのボタンでストップウォッチを作成するには、次の手順をXNUMXつずつ実行してください。

まず、XNUMXつのコマンドボタンを挿入します。

1に設定します。 OK をクリックします。 Developer > インセット > コマンドボタン、スクリーンショットを参照してください:

doc create ストップウォッチ 2

2。 次に、マウスをドラッグしてボタンを描画します。ボタンを挿入した後、ボタンのキャプションを変更できます。クリックしてください Developer > プロパティ、で プロパティ ダイアログで、新しいキャプション「開始の横にあるテキストボックスのこのボタンの「」 キャプション、スクリーンショットを参照してください:

doc create ストップウォッチ 3 2 doc create ストップウォッチ 4

3。 上記のXNUMXつの手順を繰り返して、他のXNUMXつのボタンを挿入し、「Force Stop"と"リセット」、スクリーンショットを参照してください:

doc create ストップウォッチ 5

4。 ボタンを挿入した後、をクリックしてデザインモードを終了する必要があります Developer > デザインモード.

次に、VBAコードを作成します。

5。 次に、現在のワークシートタブを右クリックして、 コードを表示、飛び出した アプリケーション向け Microsoft Visual Basic ウィンドウに、次のコードをコピーして貼り付けてください シート コード:

VBAコード:ストップウォッチを作成します:

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 create ストップウォッチ 6

Note:上記のコードでは、 C2 ストップウォッチ時間が挿入されるセルであり、 コマンドボタン1, コマンドボタン2, コマンドボタン3 ボタン名は、から正確なボタン名を表示できます 名前ボックス、スクリーンショットを参照してください:

doc create ストップウォッチ 7

第三に、ストップウォッチタイムセルをフォーマットします。

6。 次に、タイムセルを次のようにフォーマットする必要があります テキスト フォーマットし、必要に応じてセルサイズ、フォント、フォントの色、背景などを変更できます。スクリーンショットを参照してください。

doc create ストップウォッチ 8

7。 上記の手順を終えた後、これからクリックすると 開始 ボタンをクリックすると、今から時間が始まります。 Force Stop ボタン、それは時間を停止します、 リセット ボタンは時間をリセットします。スクリーンショットを参照してください。

doc create ストップウォッチ 9


デモ:VBAコードを使用して、XNUMXつのボタンでストップウォッチを作成します

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
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