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

Excelのコマンドボタンで(現在の)日付と時刻を更新または挿入するにはどうすればよいですか?

通常、多くのExcelユーザーは、式= NOW()でタイムスタンプを挿入する傾向があります。 この式を使用すると、挿入されたタイムスタンプは、ブックを開くたびに自動的に更新されます。 ワークシートの日付と時刻をいつでも手動で更新するには、どのようにそれを達成するのですか? この記事では、Excelのコマンドボタンをクリックして現在の日付と時刻を更新する方法を説明します。

VBAコードを使用してコマンドボタンで日付と時刻を更新する


VBAコードを使用してコマンドボタンで日付と時刻を更新する

Excelのコマンドボタンで日付と時刻を更新するには、次のようにしてください。

1.をクリックしてコマンドボタンを挿入します Developer > インセット > コマンドボタン(ActiveXコントロール)。 スクリーンショットを参照してください:

2.挿入したコマンドボタンを右クリックして、 コードを表示 右クリックメニューから。

3.ポップアップで アプリケーション向け Microsoft Visual Basic ウィンドウの場合は、元のコードを以下のVBAコードに置き換えてください。

VBAコード:Excelのコマンドボタンで日付と時刻を更新する

Private Sub CommandButton1_Click()
    Range("A2").Value = Now()
End Sub

Note:コードでは、CommandButton1は挿入されたコマンドボタンの名前です。 また、A2は更新日時が表示されるセルです。 必要に応じて変更してください。

4. [開発者]タブでデザインモードをオフにします。 コマンドボタンをクリックすると、現在の日付と時刻がセルA2に挿入されます。

また、コマンドボタンをクリックするたびに、セルA2の日付と時刻がすぐに更新されます。


関連記事:

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

🤖 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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
How do i update the code to put the time/date stamp in the cell NEXT to the button so it applies to each row thereon
This comment was minimized by the moderator on the site
I have a question. There is a workbook that we keep on a share drive for the whole team to access. I want to add this macro to it so anytime changes are made, we can simply pres the button and the time and date will auto populate at a click. Now here is the question, from this workbook, data is pulled to other workbooks if I save a new file as "Macro-Enabled" and delete the old "Non-Macro" workbook, will the data continue to pull from this new workbook or will I need to fix all the other workbooks.
This comment was minimized by the moderator on the site
Hi Michelle,
After saving the workbook as an Macro-Enabled Excel workbook, the code still works fine.
This comment was minimized by the moderator on the site
Awesome! Thanks for this tutorial.


However, how do i insert ONLY the date in DD/MM/YYYY format?
This comment was minimized by the moderator on the site
Hi,
You can format the output cell as Short Date formatting to solve the problem.
This comment was minimized by the moderator on the site
Hi there.. this is really good basic info..


One question - how do you modify the code to put the datestamp into the NEXT row below, each time the button is pressed? (keeping the data previously written above?)


Thank you so much!
This comment was minimized by the moderator on the site
Hi,
The below VBA code will work on selected cell. When you want to insert timestampe to a cell, just select it and press the button.

Private Sub CommandButton1_Click()
Dim xRg As Range
On Error Resume Next
Set xRg = Selection
xRg.Value = Now()
End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations