انتقل إلى المحتوى الرئيسي

كيفية إدراج الطابع الزمني الحالي عندما تتغير البيانات في خلية أخرى في Excel؟

لنفترض أنك تلقيت ورقة عمل تتطلب منك تعديل البيانات في عمود معين. وبعد تعديل ورقة العمل ، تحتاج إلى إدراج الطابع الزمني المعدل للسماح للآخرين بمعرفة الخلايا التي تم تغييرها. كيفية التعامل معها؟ ستوضح لك هذه المقالة طريقة إدخال الطابع الزمني الحالي عندما تتغير البيانات في خلية أخرى في Excel كما هو موضح أدناه.

أدخل الطابع الزمني الحالي عندما تتغير البيانات الموجودة في خلية أخرى برمز VBA


أدخل الطابع الزمني الحالي عندما تتغير البيانات الموجودة في خلية أخرى برمز VBA

كما هو موضح أدناه ، تحتاج إلى ملء الطابع الزمني في العمود E إذا تم تغيير الخلايا المقابلة في العمود C. الرجاء القيام بما يلي.

1. في ورقة العمل التي تحتاج إلى تعديلها ووضع علامة عليها بالطابع الزمني ، انقر بزر الماوس الأيمن فوق علامة تبويب الورقة ثم انقر فوق عرض الرمز من قائمة النقر بزر الماوس الأيمن.

2. ثم انسخ والصق كود فبا أدناه في ملف رمز نافذة ميكروسوفت فيسوال باسيك للتطبيقات نافذة او شباك. انظر لقطة الشاشة:

كود فبا: أدخل الطابع الزمني الحالي عندما تتغير البيانات في خلية أخرى

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20180830
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 3
xTimeColumn = 5
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
    If xCol = xCellColumn Then
       Cells(xRow, xTimeColumn) = Now()
    Else
        On Error Resume Next
        Set xDPRg = Target.Dependents
        For Each xRg In xDPRg
            If xRg.Column = xCellColumn Then
                Cells(xRg.Row, xTimeColumn) = Now()
            End If
        Next
    End If
End If
End Sub

ملاحظات: في الكود ، يعني الرقم 3 أنك ستقوم بتعديل البيانات في العمود C ، ويشير الرقم 5 إلى أن الطابع الزمني سيتم ملؤه في العمود E. يرجى تغييرها بناءً على احتياجاتك.

3. اضغط على قديم + Q مفاتيح لإغلاق ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

من الآن فصاعدًا ، عند تغيير البيانات في العمود C ، سيتم ملء الطابع الزمني في الخلايا المقابلة في العمود E كما هو موضح أدناه لقطة الشاشة.

تلميح. منتقي التاريخ. أدخل التاريخ فائدة كوتولس ل إكسيل يساعدك على إدراج التاريخ بسرعة بتنسيق التاريخ المحدد في خلية محددة.
قم بتنزيله وجربه الآن! (تجربة مجانية لمدة 30 يومًا)


مقالات ذات صلة:

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
Comments (60)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hallo!

Der VBA-Code funktioniert wunderbar. Gibt es eine Möglichkeit den Code zu erweitern?

Jetzt gerade sie der Coade wie folgt aus:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20180830
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 10
xTimeColumn = 16
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Now()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
Cells(xRg.Row, xTimeColumn) = Now()
End If
Next
End If
End If
End Sub

Allerdings möchte ich gerne, dass ein Zeitstempel auch dann ausgegeben wird, wenn in Spalte 3, 4, 6, 8, 10 oder 13 eine Änderung erfolgt. WElche Änderung spielt keine Rolle, nur das es eine gab. Geht das?

Liebe Grüße
Paolo :-)
This comment was minimized by the moderator on the site
Hi OP,

Not sure if you are still seeing this. I am trying to update this so that the formula picks up a range. I want Col E:I to be updated with a timestamp if Col J:N update to "Completed". Do you have the code for that?

Thanks,
Huzefa A.
This comment was minimized by the moderator on the site
Hi Huzefa,

I don't know if I understand your question clearly. The following VBA code may help. Please give it a try.
The relationship is a 1:1 mapping between the columns. With this script, when a cell in column J is updated to "Completed", the timestamp will be inserted into the corresponding cell in column E. Similarly, updates to column K will affect column F, and so on.

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20230816
    Dim IntersectRng As Range
    Dim TargetColumn As Integer

    ' Check if the changed cell is in columns J to N
    Set IntersectRng = Application.Intersect(Target, Me.Range("J:N"))

    If Not IntersectRng Is Nothing Then
        For Each cell In IntersectRng
            ' If the changed cell's value is "Completed"
            If cell.Value = "Completed" Then
                ' Calculate the target column in E:I
                TargetColumn = cell.Column - 5
                Me.Cells(cell.Row, TargetColumn).Value = Now()
            End If
        Next cell
    End If
End Sub
This comment was minimized by the moderator on the site
How would I go about running this Macro in all of the sheets in my workbook? It is only working in the first sheet.
This comment was minimized by the moderator on the site
Hi Jon,
The following VBA code can help. Please give it a try.
Note: This VBA code needs to be added to the ThisWorkbook (Code) window.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/Thisworkbook.png
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'Updated by Extendoffice 20221208
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 3
xTimeColumn = 5
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
    If xCol = xCellColumn Then
       Cells(xRow, xTimeColumn) = Now()
    Else
        On Error Resume Next
        Set xDPRg = Target.Dependents
        For Each xRg In xDPRg
            If xRg.Column = xCellColumn Then
                Cells(xRg.Row, xTimeColumn) = Now()
            End If
        Next
    End If
End If
End Sub
This comment was minimized by the moderator on the site
Hallo !
Ich habe noch eine Frage zu dem oben angegebenen VBA-Code.
Bei meiner Tabelle befindet sich der Wert, für den der Zeitstempel erstellt werden soll in Spalte G.
Der Wert in G errechnet sich aus der Summe der Werte in den Spalten K:AA.
Die Werte in K:AA ergeben sich aus einem anderen Tabellenblatt, unter Benutzung der Zählenwenn-Funktion.
Wenn die Werte direkt in K:AA eingegeben werden aktualisiert sich der Zeitstempel wie gewünscht.
Wenn die Werte in K:AA durch "Zählenwenn" aus einem anderen Tabellenblatt aktualisiert werden, ändert sich der Zeitstempel nicht.

Hat jemand eine Lösung für mein Problem ?
This comment was minimized by the moderator on the site
Hello Michael Rasche,
The formula issue cannot be handled yet. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hallo,
ich möchte auch gerne in einer Tabelle einen Zeitstempel setzen, und bin bei der Suche auf diese Seite gestossen.
Ich habe alles wie oben beschrieben eingegeben, jetzt ergibt sich noch folgendes Problem:
Der Zeitstempel soll sich ändern, wenn sich der Wert in Spalte G ändert, der Wert in Spalte bildet sich aus der Summe mehrerer Zellen (z.B. K 150 - AA 150) in der Reihe.
Wenn ich einen neuen Wert direkt in die Zellen eingebe funktioniert das VBA.
Bei meiner Tabelle ändern sich die Werte in z.B. K 150 - AA 150 aber durch die "Zählenwenn" Funktion aus einem anderen Tabellenblatt, wenn sich dann die Summe erhöht, ändert sich der Zeitstempel nicht.
Hat jemand eine Lösung für mich ?
This comment was minimized by the moderator on the site
how do I add this on two columns? to have two timestamps for two column on input???
This comment was minimized by the moderator on the site
Hi, finally I found this post. Thankyou I Needed this. But can anyone help me, I want to change the code so that instead of tracking the changes on the current worksheet, I want the code to track the changes on selected Columns from other worksheet, then insert the timestamp to the current worksheet.
This comment was minimized by the moderator on the site
Hi, finally i found this post. Thankyou I Needed this. But can anyone help me, I want to change the code so that instead of tracking the changes on the current worksheet, I want the code to track the changes on selected Columns from other worksheet, then insert the timestamp to the current worksheet.
This comment was minimized by the moderator on the site
Hi, This is great info, but I'm having problem. I would like to use for change in column A time stamp column B and change in column D with time stamp column E and change in column G with time stamp column H. I can not figure out. Help please.
This comment was minimized by the moderator on the site
Hi, Is there a chance you can help me? I have tried the VBA code for the timestamp:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20180830
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 3
xTimeColumn = 5
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Now()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
Cells(xRg.Row, xTimeColumn) = Now()
End If
Next
End If
End If
End Sub

My problem is that I have to add dates in column 22 and I need the timestamp in column 21. The above code does not work in my sheet. I have tried it with timestamp functions and formulas, but it always changes it to the date when I opened the workbook.
I also tried to work with conditional formatting that the another cell changes the colour when the cell with the timestamp is not todays date, but this does not work either. Can you let me know what I do wrong?
This comment was minimized by the moderator on the site
Hi Lina,
Do you mean manually enter dates in column 22 and then populate timestamp automatically in adjacent cells in column 21?
You just need to change the column numbers in the code to get it down. If you only want to display time, replace the NOW() with Time() in the code. See the below code.

<div data-tag="code">Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 20201106
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 22
xTimeColumn = 21
xRow = Target.Row
xCol = Target.Column
If Target.Text <> "" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Time()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
Cells(xRg.Row, xTimeColumn) = Time()
End If
Next
End If
End If
End Sub
This comment was minimized by the moderator on the site
Thank you for your response. Yes, that's what I wanted to do. I tried the above VBA code before but for some reason it did not work, but it works fine now. Thank you for your help
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