Ana içeriğe atla

Hücre değiştiğinde tarih ve saat otomatik olarak nasıl kaydedilir?

Manuel olarak statik tarih ve saat eklemek veya bir formülle sistem saatiyle değişen dinamik bir tarih eklemek bizim için kolaydır. Değerleri değiştirdiğinizde veya girdiğinizde tarih ve saati otomatik olarak kaydetmek istiyorsanız, bu sorunun üstesinden gelmek biraz farklı olabilir. Ancak bu yazıda aşağıdaki adımlarla bu görevi çözebilirsiniz.

VBA kodu ile hücre değiştiğinde tarih ve saati otomatik olarak kaydedin


ok mavi sağ balon VBA kodu ile hücre değiştiğinde tarih ve saati otomatik olarak kaydedin

Örneğin, bir dizi değerim var ve şimdi, Sütun B'de yeni değerleri değiştirdiğimde veya yazdığımda, gösterilen aşağıdaki ekran görüntüsü gibi Sütun C'de geçerli tarih ve saati otomatik olarak kaydetmesini istiyorum:

doc-güncelleme-zaman-değer-değişiklikleri-1

Bu görevi aşağıdaki VBA kodu ile tamamlayabilirsiniz. Lütfen şunu yapın:

1. Basılı tutun ALT + F11 tuşlarını açmak için Uygulamalar için Microsoft Visual Basic penceresi.

2. Ardından soldan kullanılmış çalışma sayfanızı seçin Proje Gezginiaçmak için çift tıklayın modülve ardından aşağıdaki VBA kodunu kopyalayıp boş Modüle yapıştırın:

VBA kodu: Hücre değiştiğinde tarih ve saati otomatik olarak kaydedin

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = Now
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If
End Sub

doc-güncelleme-zaman-değer-değişiklikleri-1

3. Ardından çalışma sayfasına dönmek için bu kodu kaydedin ve kapatın, şimdi hücre değerini değiştirdiğinizde veya Sütun B'ye yeni veri yazdığınızda, tarih ve saat otomatik olarak Sütun C'ye kaydedilecektir.

Notlar:

1. Yukarıdaki kodda, "B: B"Bu komut dosyasındaki hücre değerlerini değiştirmek istediğiniz diğer herhangi bir sütuna: WorkRng = Kesişim (Application.ActiveSheet.Range ("B: B"), Hedef) ayarla.

2. Bununla xOfsetSütunu = 1 komut dosyası, değişen değer sütununuzun yanındaki ilk sütuna tarih ve saati ekleyebilir ve güncelleyebilirsiniz, 1 sayısını 2,3,4,5 gibi diğer sayılarla değiştirebilirsiniz ... bu, tarihin ekleneceği anlamına gelir. değiştirilen değerler sütununun yanında ikinci, üçüncü, dördüncü veya beşinci sütun.

3. Değiştirilen sütundaki bir değeri sildiğinizde, tarih ve saat de kaldırılacaktır.

En İyi Ofis Üretkenlik Araçları

🤖 Kutools AI Yardımcısı: Aşağıdakilere dayalı olarak veri analizinde devrim yaratın: Akıllı Yürütme   |  Kodunu oluşturun  |  Özel Formüller Oluşturun  |  Verileri Analiz Edin ve Grafikler Oluşturun  |  Kutools İşlevlerini Çağır...
Popüler Özellikler: Yinelenenleri Bul, Vurgula veya Tanımla   |  Boş Satırları Sil   |  Veri Kaybı Olmadan Sütunları veya Hücreleri Birleştirin   |   Formülsüz Tur ...
Süper Arama: Çoklu Ölçütlü VLookup    Çoklu Değer VLookup  |   Birden Çok Sayfada VLookup   |   Bulanık Arama ....
Gelişmiş Açılır Liste: Hızla Açılır Liste Oluşturun   |  Bağımlı Açılır Liste   |  Çoklu Seçim Açılır Liste ....
Sütun Yöneticisi: Belirli Sayıda Sütun Ekleme  |  Sütunları Taşı  |  Gizli Sütunların Görünürlük Durumunu Değiştir  |  Aralıkları ve Sütunları Karşılaştırın ...
Öne Çıkan Özellikler: Izgara Odağı   |  Tasarım görünümü   |   Büyük Formül Çubuğu    Çalışma Kitabı ve Sayfa Yöneticisi   |  Kaynak Kütüphanesi (Otomatik metin)   |  Tarih Seçici   |  Çalışma Sayfalarını Birleştirin   |  Hücreleri Şifrele/Şifresini Çöz    E-postaları Listeye Göre Gönder   |  Süper Filtre   |   Özel Filtre (kalın/italik/üstü çizili filtre...) ...
En İyi 15 Araç Seti12 Metin Tools (Metin ekle, Karakterleri Kaldır, ...)   |   50+ Grafik Türleri (Gantt şeması, ...)   |   40+ Pratik Formüller (Yaşı doğum gününe göre hesapla, ...)   |   19 sokma Tools (QR Kodunu Girin, Yoldan Resim Ekle, ...)   |   12 Dönüştürme Tools (Sayılardan Kelimelere, Para Birimi Dönüştürme, ...)   |   7 Birleştir ve Böl Tools (Gelişmiş Kombine Satırları, Bölünmüş hücreler, ...)   |   ... ve dahası

Kutools for Excel ile Excel Becerilerinizi Güçlendirin ve Daha Önce Hiç Olmadığı Gibi Verimliliği Deneyimleyin. Kutools for Excel, Üretkenliği Artırmak ve Zamandan Tasarruf Etmek için 300'den Fazla Gelişmiş Özellik Sunar.  En Çok İhtiyacınız Olan Özelliği Almak İçin Buraya Tıklayın...

Açıklama


Office Tab, Office'e Sekmeli Arayüz Getirir ve İşinizi Çok Daha Kolay Hale Getirir

  • Word, Excel, PowerPoint'te sekmeli düzenlemeyi ve okumayı etkinleştirin, Publisher, Access, Visio ve Project.
  • Yeni pencereler yerine aynı pencerenin yeni sekmelerinde birden çok belge açın ve oluşturun.
  • Üretkenliğinizi% 50 artırır ve her gün sizin için yüzlerce fare tıklamasını azaltır!
Comments (109)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi,
Is it is also possible to have a VBA code that is able to create a timestamp for cells that have a formula in it? So when the value changes (changes from empty cell to a cell with a value >0 in it) the timestamp appears?
Kind regards,
Femke
This comment was minimized by the moderator on the site
Hello, Femke,
To solve your problem, please apply the below VBA code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby ExtendOffice
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Dim xDRg As Range

On Error Resume Next
Set xDRg = Target.DirectDependents

If Not xDRg Is Nothing Then

Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), xDRg)

xOffsetColumn = 1
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = Now
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If
Else
Set WorkRng = Intersect(Application.ActiveSheet.Range("B:B"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
    Application.EnableEvents = False
    For Each Rng In WorkRng
        If Not VBA.IsEmpty(Rng.Value) Then
            Rng.Offset(0, xOffsetColumn).Value = Now
            Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
        Else
            Rng.Offset(0, xOffsetColumn).ClearContents
        End If
    Next
    Application.EnableEvents = True
End If

End If
End Sub


Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Sir ! I have a problem that I have data entering Column B in sheet 1 and Date Column C in sheet 2....please guide me what will be the code for that...Anyone
This comment was minimized by the moderator on the site
I want to use this code to update multiple cells within the same sheet. How do I write this?For example, when cell C12 changes, C13 gets the datewhen cell C26 changes, C27 gets the date
when cell G13 changes, G14 gets the date
and so on
This comment was minimized by the moderator on the site
datetime    auto_cycle    tool    time_difference
01-01-2021 :10:10:09    1    1    00:00:11
03-01-2021 :10:10:20    1    2    00:00:02
13-10-2021 :10:10:22    1    3    00:00:04
13-10-2021 :10:10:26    1    4    00:00:04
13-10-2021 :10:10:30    1    5    00:00:06
13-10-2021 :10:10:36    1    6    00:00:02
13-10-2021 :10:10:38    1    7    00:00:05
13-10-2021 :10:10:43    1    8    00:00:00
13-10-2021 :10:10:43    1    9    00:00:06
13-10-2021 :10:10:49    1    10    00:00:03
13-10-2021 :10:10:52    1    11    00:00:08
13-10-2021 :10:11:00    1    13    00:00:10
13-10-2021 :10:11:10    1    12    00:00:04
13-10-2021 :10:11:14    1    14    00:00:05
13-10-2021 :10:11:19    1    16    00:00:04
13-10-2021 :10:11:23    1    17    00:00:04
13-10-2021 :10:11:27    1    18    00:00:02
13-10-2021 :10:11:29    1    19    00:00:04
13-10-2021 :10:11:33    1    20    00:00:05
13-10-2021 :10:11:38    1    21    00:00:07
13-10-2021 :10:11:45    1    12    

this is my master file suppose i change the time value in a column corresponding time difference sshould be update in d column automatically without trigger the macro assigning button could you please help me out 
This comment was minimized by the moderator on the site
I see a couple of people asking about formulas and I'm sorry if I missed the answer somewhere in the thread. I am updating very large data sets that then are migrated to hidden sheets. I have those sheets each set with this "latest update" code but since everything on those sheets references back to the larger data set, it does not see a cell update as the formulas remain the same even thought the values change. I need it to update when the value changes and not jus when the content of the cell changes.
This comment was minimized by the moderator on the site
Sir ! Did you find solution of your problem then please share it with me.I am also facing the same issue...I am new in this...Please
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("A:A"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub

This comment was minimized by the moderator on the site
1 26-02-2021, 11:32:49
1 26-02-2021, 11:32:49
1 26-02-2021, 11:32:49
1 26-02-2021, 11:32:49
1 26-02-2021, 11:32:50
1 26-02-2021, 11:32:50
1 26-02-2021, 11:32:50
1 26-02-2021, 11:32:50
1 26-02-2021, 11:32:50
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04
0 26-02-2021, 11:33:04

Why on 0 value its getting date.. when cell have data then only get date otherwise show balnk...how we can do it vba code
This comment was minimized by the moderator on the site
Hi,The code works perfect but if changed the data in A i was wondering if i could have the date in column B and the time in Column D?Thanks for any help.
This comment was minimized by the moderator on the site
Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("J:J"), Target)
xOffsetColumn = 1
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
xOffsetColumn = 2
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
End Sub
This comment was minimized by the moderator on the site
Hi,If i were to have 2 columns duplicating the same macros, how can that be possible.
I want to show the date and time in column B for values changed in A; while also wanting to show the time and date in column D for values changed in C.
This comment was minimized by the moderator on the site
Hi Extend Office, thank you for guiding me.I am a beginner , i had this problem which i saw some of your faced. This was the situationFor e.g
You want your date and time shown in Column A when any other column of the same row B:AZ for example got their values changed.So heres my solution. Please correct me if the code has any issues. TIA.
Private Sub Worksheet_Change(ByVal Target As Range)

Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("B:AZ"), Target)'B:AZ put your own columns'rownumber=Activecell.Row will not work because it it will locate the adjacent row after you press enter or when ur mouse click on other cells
rownumber = Target.Row
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Range("A" & rownumber).Value = Now 'gives A and the adjacent row number
Range("A" & rownumber).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
End If
Next
Application.EnableEvents = True
End If
End Sub



Thank you.
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