跳到主要內容

在Excel中快速自動插入日期和時間戳

在Excel中,插入日期和時間戳是正常操作。 在本教程的此處,我將通過提供不同的情況介紹在Excel單元格中手動或自動插入日期和時間戳的多種方法。

使用快捷方式插入日期和時間戳

使用公式插入日期和時間戳

在另一列中輸入數據時自動插入時間戳的公式

VBA在另一列中輸入數據時自動插入時間戳


使用快捷方式插入日期和時間戳

如果只需要在幾個單元格中插入日期和時間戳,則可以通過按快捷鍵手動插入它們。

插入當前日期: 控制 + :
doc插入時間戳1

插入當前時間: 轉移 + 控制 + :
doc插入時間戳2

見截圖:
doc插入時間戳3

提示:

1.您可以根據需要將輸出格式設置為日期格式或時間格式。 單元格格式 對話。

2。 如果你有 Excel的Kutools,您可以根據需要將當前日期或其他日期以指定的日期格式插入 插入日期 的功能。 點擊免費下載
插入日期


使用公式插入日期和時間戳

如果要插入可以自動更新的日期或時間戳,可以使用以下公式。

插入當前日期

=今天()

媒體推薦 Enter 鍵,並將當前日期插入到單元格中。

插入當前時間:

=現在()

按Enter鍵,當前日期和時間將插入到單元格中。
doc插入時間戳4

提示:

1.您可以根據需要將輸出格式設置為日期格式或時間格式。 單元格格式 對話。 例如,您只想顯示當前時間,只需在使用 =現在()

2.如果要將當前日期和時間插入工作表的頁眉或頁腳,則可以使用 插入工作簿信息 功能 Excel的Kutools 快速處理這項工作。 點擊免費下載
插入工作簿信息


在另一列中輸入數據時自動插入時間戳的公式

假設有兩列,即A列和B列,現在您想在A列中輸入數據時在B列中插入當前時間戳,該如何做?
自動插入timstamp 1

輸入數據時自動插入時間戳

1.首先,單擊 文件 > 選項 打開 Excel選項 對話框中,選擇 公式 在左窗格中,然後檢查 啟用迭代計算 in 計算選項 組。 然後點擊 OK.
doc插入時間戳5

2.在B列(例如,單元格B1)中,鍵入以下公式

= IF(A1 <>“”,IF(B1 <>“”,B1,NOW()),“”)

然後將自動填充手柄向下拖動到單元格。
doc插入時間戳6

3.然後根據需要在公式中將公式單元格設置為日期時間格式。 單元格格式 對話框:保持公式單元格處於選中狀態,右鍵單擊以顯示上下文菜單,選擇 單元格格式,然後 單元格格式 對話框彈出 習俗 在哪個部分 聯繫電話 標籤,在其中輸入所需的格式 類別 文本框,然後單擊 OK.
doc插入時間戳7

現在,當您在列A中輸入數據時,當前日期時間將插入到列B中。
doc插入時間戳8

當單元格在另一列中更改時自動插入和更新時間戳

如果要在單元格輸入時自動插入時間戳,並且同時更改條目,則插入的時間戳將被更新,可以使用以下公式:

=IF(A1<>"",IF(AND(B1<>"",CELL("address")=ADDRESS(ROW(A1),COLUMN(A1))),NOW(),IF(CELL("address")<>ADDRESS(ROW(A1),COLUMN(A1)),B1,NOW())),"")

A1是您將輸入數據的單元格,B1是您要插入時間戳的公式的單元格。

向下拖動自動填充手柄,使您使用的單元格。
自動插入timstamp 2

然後,根據需要在公式單元格中將其設置為日期時間格式 單元格格式 對話框:保持公式單元格處於選中狀態,右鍵單擊以顯示上下文菜單,選擇 單元格格式,然後 單元格格式 對話框彈出 習俗 在哪個部分 聯繫電話 標籤,在其中輸入所需的格式 類別 文本框,單擊 OK.


VBA在另一列中輸入數據時自動插入時間戳

如果您熟悉VBA代碼,則可以執行以下操作:

1.右鍵單擊您使用的工作表選項卡,然後選擇 查看代碼 從上下文菜單。
doc插入時間戳9

2.然後在 Microsoft Visual Basic for Applications 窗口,粘貼下面的代碼。

VBA:自動插入時間戳

Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyKutools20190919
Dim xRInt As Integer
Dim xDStr As String
Dim xFStr As String
On Error Resume Next
xDStr = "A" 'Data Column
xFStr = "B" 'Timstamp Column
If (Not Application.Intersect(Me.Range(xDStr & ":" & xDStr), Target) Is Nothing) Then
       xRInt = Target.Row
       Me.Range(xFStr & xRInt) = Format(Now(), "mm/dd/yyyy hh:mm:ss")
End If
End Sub

doc插入時間戳10

3.然後保存此代碼。 從現在開始,只要您在A列中輸入數據或更改數據,新的時間戳就會插入到B列中。

備註:您可以在VBA代碼中更改A和B列以及mm / dd / yyyy hh:mm:ss時間格式,以符合您的實際需求。

如果要使用定義的函數,可以執行以下操作:

1。 保持 Alt + F11鍵 啟用 Microsoft Visual Basic for Applications 窗口。 然後點擊 插入 > 模塊 插入空白模塊。
doc插入時間戳11

2.將下面的代碼粘貼到新模塊中。 然後保存代碼並返回工作表。

Function FormatDate(xRg As Range)
'UpdatebyKutools20190919
On Error GoTo Err_01
If xRg.Value <> "" Then
    FormatDate = Format(Now, "mm/dd/yyyy hh:mm:ss")
Else
    FormatDate = ""
End If
Exit Function
Err_01:
    FormatDate = "Error"
End Function

doc插入時間戳12

3.在將插入時間戳的單元格中,鍵入此公式

= FormatDate(F1)

F1是您要輸入數據或更改數據的單元格。 然後將自動填充手柄向下拖動到單元格。
doc插入時間戳13

現在,如果單元格F1輸入數據或已更新,則將插入當前日期時間。


與DateTime相關的其他操作(文章)

將存儲為文本的日期轉換為Excel中的日期
有時,當您將日期從其他數據源複製或導入到Excel單元格時,日期可能會格式化並存儲為文本。 在這裡,我介紹了一些技巧,可以將這些以文本形式存儲的日期轉換為Excel中的標準日期。

在Excel中添加或減去半年/月/小時的日期或時間
在我們的Excel日常工作中通常要添加年,月或小時的日期或時間。 您是否曾經嘗試添加半年,一個月或一個小時的日期或時間? 在這裡,我介紹了處理此工作的技巧。

Excel中一天的平均時間戳
例如,您已經記錄了特定用戶每次在Excel中訪問網站時的登錄時間戳,現在您希望將這些時間戳取平均值,以預測該用戶將來訪問該網站的最長時間,如何完成它?

在Excel中計算午夜之後的時間之間的小時數
假設您有一個時間表來記錄您的工作時間,則A列中的時間是今天的開始時間,B列中的時間是第二天的結束時間。 通常,如果您直接減去“ = B2-A2”來計算兩次之間的時間差,則不會顯示正確的結果


  • 超級公式欄 (輕鬆編輯多行文本和公式); 閱讀版式 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 和保存數據; 拆分單元格內容; 合併重複的行和總和/平均值...防止細胞重複; 比較範圍...
  • 選擇重複或唯一 行; 選擇空白行 (所有單元格都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇...
  • 確切的副本 多個單元格,無需更改公式參考; 自動創建參考 到多張紙; 插入項目符號,複選框等...
  • 收藏并快速插入公式,範圍,圖表和圖片; 加密單元 帶密碼 創建郵件列表 並發送電子郵件...
  • 提取文字,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級濾鏡 (將過濾方案保存並應用於其他工作表); 高級排序 按月/週/日,頻率及更多; 特殊過濾器 用粗體,斜體...
  • 結合工作簿和工作表; 根據關鍵列合併表; 將數據分割成多個工作表; 批量轉換xls,xlsx和PDF...
  • 數據透視表分組依據 週號,週幾等 顯示未鎖定的單元格 用不同的顏色 突出顯示具有公式/名稱的單元格...
kte選項卡201905
  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
officetab底部
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
If anyone can assist, I'm seeking help to create a formula that, when I change the status to 'Complete,' automatically records the date of that moment. Similarly, if I change the status for subsequent entries, it should capture the date of that day. Any guidance on creating this formula would be greatly appreciated.
This comment was minimized by the moderator on the site
Hi, We have used the following formula for auto-update timestamp

=IF(A1<>"",IF(AND(B1<>"",CELL("address")=ADDRESS(ROW(A1),COLUMN(A1))),NOW(),IF(CELL("address")<>ADDRESS(ROW(A1),COLUMN(A1)),B1,NOW())),"")

But, sometimes it works sometimes it doesn't. even faced for some user's it's working fine for some not.
Sometimes it shows circular reference pop message error for some-user.
when tried to rectify the error, we saw circular reference is grad out. Not sure how do we fix it.

Any help much apricated!!! Thankyou
This comment was minimized by the moderator on the site
Hi, thank you for this, it is very helpful with my project.

I' m running calculations on stock market information that is populating the spreadsheet with RTD;
I' m trying to create a timestamp when there is an update in the stock price, but this does not work, the "timestamp" cell remains blank.
(The cell that receives the stock price is RTD formula)

Any ideas what i should do ?
This comment was minimized by the moderator on the site
In the cells where the time stamp should show up, red text saying Time stamp shows up instead. No value in format mm/dd/yyyy hh:mm:ss is visible.
This comment was minimized by the moderator on the site
Hi, Celeste, I did not get your question clearly. If you want to show "Time Stamp" in the cell if there is empty in the entried cell, you just change the formula to:
=IF(A1<>"",IF(B1<>"",B1,NOW()),"Time Stamp")
This comment was minimized by the moderator on the site
the function uptades every time you open the excel file
it also updates the earlier data when you insert rows.
This comment was minimized by the moderator on the site
Hi, try to click Formulas tab and go to Calculation group to click Calculation Options > Manual, then the formula will not auto update.
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-manual-calculation.png
This comment was minimized by the moderator on the site
Thank you very much for your kind help. Unfortunately, the manual setting would stop my other formulas in the table, which is not good from my point of view.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations