Note: The other languages of the website are Google-translated. Back to English
Oturum aç  \/ 
x
or
x
Kaydol  \/ 
x

or

Excel'de çift tıklayarak bir hücreye geçerli tarih / saati otomatik olarak nasıl ekleyebilirim / girebilirim?

Bir çalışma sayfasına sık sık geçerli tarih veya tarih saati eklemeniz gerekiyorsa, bu makaledeki yöntemi deneyebilirsiniz. Bu makale, yalnızca çift tıklama ile belirli bir aralıktaki hücrelerde geçerli tarih veya tarih türünü otomatik olarak eklemenize veya girmenize yardımcı olacaktır.

VBA kodu ile geçerli tarih veya tarih saatini otomatik eklemek / girmek için çift tıklayın


VBA kodu ile geçerli tarih veya tarih saatini otomatik eklemek / girmek için çift tıklayın


Bir hücreye çift tıklayarak otomatik olarak geçerli tarih veya tarih saati eklemek için aşağıdaki VBA kodunu çalıştırabilirsiniz. Lütfen aşağıdaki işlemleri yapın.

1. Belirtilen hücrelere geçerli tarihi eklemek istediğiniz Sayfa sekmesine sağ tıklayın ve ardından Kodu Görüntüle sağ tıklama menüsünden.

2. içinde Uygulamalar için Microsoft Visual basic penceresinde aşağıdaki VBA kodunu kopyalayıp Kod penceresine yapıştırın.

VBA kodu: Geçerli tarihi bir hücreye eklemek için çift tıklayın

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
    End If
End Sub

notlar:

1. Kodda, A1: B10, geçerli tarihi ekleyeceğiniz aralıktır.
2. Hücreye geçerli tarih saatini eklemeniz gerekiyorsa, lütfen değiştirin Tarih ile Şimdi () kodda. Bunları ihtiyaç duyduğunuz şekilde değiştirebilirsiniz.

3. Basın Ara Toplam + Q kapatmak için aynı anda tuşları Uygulamalar için Microsoft Visual Basic penceresini açın ve çalışma sayfasına dönün.

Şu andan itibaren, belirtilen A1: B10 aralığındaki herhangi bir hücreye çift tıklandığında. Geçerli tarih veya tarih saati otomatik olarak girilecektir.


İlgili Makaleler:


En İyi Ofis Üretkenliği Araçları

Kutools for Excel Sorunlarınızın Çoğunu Çözer ve Verimliliğinizi% 80 Artırır

  • Yeniden: Hızlıca yerleştirin karmaşık formüller, grafikler ve daha önce kullandığınız her şey; Hücreleri Şifrele şifre ile; Posta Listesi Oluşturun ve e-posta gönder ...
  • Süper Formül Çubuğu (birden çok metin ve formül satırını kolayca düzenleyin); Okuma Düzeni (çok sayıda hücreyi kolayca okuyun ve düzenleyin); Filtrelenmiş Aralığa Yapıştır...
  • Hücreleri / Satırları / Sütunları Birleştirme Veri kaybetmeden; Bölünmüş Hücre İçeriği; Yinelenen Satırları / Sütunları Birleştirme... Yinelenen Hücreleri Önleyin; Aralıkları Karşılaştır...
  • Yinelenen veya Benzersiz'i seçin Satırlar; Boş Satırları Seçin (tüm hücreler boştur); Süper Bul ve Bulanık Bul Birçok Çalışma Kitabında; Rastgele Seçim ...
  • Tam kopya Formül referansını değiştirmeden Birden Çok Hücre; Otomatik Referans Oluştur Birden Çok Sayfaya; Madde İşaretleri Ekle, Onay Kutuları ve daha fazlası ...
  • Metni Çıkar, Metin Ekle, Konuma Göre Kaldır, Alanı Kaldır; Sayfalama Alt Toplamları Oluşturma ve Yazdırma; Hücre İçeriği ve Yorumları Arasında Dönüştür...
  • Süper Filtre (filtre şemalarını kaydedin ve diğer sayfalara uygulayın); Gelişmiş Sıralama ay / hafta / gün, sıklık ve daha fazlasına göre; Özel Filtre kalın, italik ...
  • Çalışma Kitaplarını ve Çalışma Sayfalarını Birleştirin; Tabloları anahtar sütunlara göre birleştirin; Verileri Birden Çok Sayfaya Bölme; Toplu dönüştürme xls, xlsx ve PDF...
  • 300'den fazla güçlü özellik. Office / Excel 2007-2019 ve 365'i destekler. Tüm dilleri destekler. Kuruluşunuzda veya kuruluşunuzda kolay dağıtım. Tam özellikli 30 günlük ücretsiz deneme. 60 günlük para iade garantisi.
kte sekmesi 201905

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!
ofis tabanı
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Joe · 1 years ago
    This was just what I was looking for - this save a ton of time and I appreciate the well written instructions. Thank you!

  • To post as a guest, your comment is unpublished.
    Lee Hoemann · 1 years ago
    So I inserted code and it works great on several sheets in my workbook, however on some sheets it just suddenly stops working after a certain row even though I have the correct range entered. Any thoughts on why this might happen.
  • To post as a guest, your comment is unpublished.
    Heather · 2 years ago
    Does anyone know if there is a way to insert this code into Excel Online? I had used it with the desktop version and it worked great but now we have migrated everything to the online platform and my date and time stamps on double click have disappeared and I can't figure out how to view or edit the code. Thanks.
  • To post as a guest, your comment is unpublished.
    Dylan · 2 years ago
    Love the code and it works great. How can I make it so when I double click to execute the code its shows time in military time?
    • To post as a guest, your comment is unpublished.
      Heather · 2 years ago
      I would think that if you just select the Military Time format for that cell from the Number -> Time format options that should do it. For example, you would select 13:30 instead of 1:30 PM, and then it should display in military time.
    • To post as a guest, your comment is unpublished.
      Heather · 2 years ago
      I think if you select the military time format for that cell from the Format -> Number -> Time options in your sheet that ought to work. For example, it gives the option of 1:30 PM or 13:30, so you would just select 13:30 and that should do it.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Hi Dylan,
      Sorry can't help you with that yet. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Max · 2 years ago
    Hi there,

    I copied and pasted the above code exactly as it is written into a blank workbook, however, it does not work for me. I looked at different sources on the web and most sites have a similar format as what is written above. I think perhaps there is something wrong with my VBA or some settings are not turned on. Any advice would be much appreciated. I am running Excel for Office 365 MSO (16.0.11001.20097) 32-bit on Windows 10.
  • To post as a guest, your comment is unpublished.
    Trav · 3 years ago
    Hello, the above code worked great for me. Now i am just wondering if there is a way to have the text "Double click to enter date" appear in the cell until the date is entered. My goal is to make the document be as user friendly as possible. Thank you in advance
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Hi Travis,
      We can’t modify the code to have text display in the cell directly. But alternatively, the below optimized code will help to display the text in the cell comment, and the comment will be removed automatically after double click the cell to enter date.

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
      Target.NoteText "double click to add date"
      End If
      End Sub

      Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
      Cancel = True
      Target.Comment.Delete
      Target.Formula = Date
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Tee · 3 years ago
    Hello, the code you gave works great. I am just curious if there is any way to have the text "double click to add date" In the cell until the date is entered. Thank you in advance ( I am trying to make my document as user friendly as possible as to not confuse my co-workers)
  • To post as a guest, your comment is unpublished.
    Dre · 3 years ago
    I copied and pasted the code updating the range and it did not work :-(


    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("B4:B100")) Is Nothing Then
    Cancel = True
    Target.Formula = Now()
    End If
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good day,
      The code works well in my case. Can you tell me your Office version?
  • To post as a guest, your comment is unpublished.
    Paul · 3 years ago
    The double click entery code created is:


    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A1:a1000")) Is Nothing Then
    Cancel = True
    Target.Formula = Date
    End If

    If Not Intersect(Target, Range("b1:b1000")) Is Nothing Then
    Cancel = True
    Target.Formula = Time
    End If

    If Not Intersect(Target, Range("g1:g1000")) Is Nothing Then
    Cancel = True
    Target.Formula = Time
    End If
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Paul,
      Please try the following VBA code.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg As Range
      On Error Resume Next
      Set xRg = Intersect(Range("A1:a1000,b1:b1000,G1:G1000"), Target)
      If xRg Is Nothing Then Exit Sub
      Target.Worksheet.Unprotect Password:="123"
      xRg.Locked = True
      Target.Worksheet.Protect Password:="123"
      End Sub

      Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      Application.EnableEvents = False
      ActiveSheet.Unprotect Password:="123"
      If Not Intersect(Target, Range("A1:a1000")) Is Nothing Then
      Cancel = True
      Target.Formula = Date
      End If
      If Not Intersect(Target, Range("b1:b1000")) Is Nothing Then
      Cancel = True
      Target.Formula = Time
      End If
      If Not Intersect(Target, Range("g1:g1000")) Is Nothing Then
      Cancel = True
      Target.Formula = Time
      End If
      ActiveSheet.Protect Password:="123"
      Application.EnableEvents = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Paul · 3 years ago
    The code really works... Thank you...i have added another code to protect the cell after the entry of data. Now the problem is that, once i enter the data and the cell is protected and by mistake if I double click the protected cell, then the above code goes wrong for the whole sheet. It does not work then. I have to unprotect the sheet to bring the code live. Any solution?

    The protection Code used is below:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xRg As Range
    On Error Resume Next
    Set xRg = Intersect(Range("A1:a1000,b1:b1000,G1:G1000"), Target)
    If xRg Is Nothing Then Exit Sub
    Target.Worksheet.Unprotect Password:="123"
    xRg.Locked = True
    Target.Worksheet.Protect Password:="123"
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Sorry I get your point. (miss the above code)
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Paul,
      I try the code you provided. The entire worksheet will be protected immediately once I enter data into any one of the specified protected cells.
      Besides, when double click on the protected cell, nothing changes to the code in my case.
      Would you explain what you are exactly trying to do with the code?
  • To post as a guest, your comment is unpublished.
    Joel · 4 years ago
    How do we extend this to add more cell range? I added a these extra cell ranged to the code : (Target, Range("C10:C19", "D10:D19", "E10:E19")) however it is giving me a compile error saying "wrong number of arguments or invalid property assignments" and then it highlights the first line of code you supplied "Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)" Please assist me.
    • To post as a guest, your comment is unpublished.
      Nick · 4 years ago
      Joel, don't know if you are still looking for a solution, but you need to change your code:

      From: (Target, Range("C10:C19", "D10:D19", "E10:E19"))
      To: (Target, Range("C10:C19,D10:D19,E10:E19"))

      This will do it for you.
      • To post as a guest, your comment is unpublished.
        Attila · 4 years ago
        Hello Nick,
        I'd like to get some advise from you on this subject....
        I have a file that I call "productivity sheet".... On this sheet I'd like to insert the actual time,in selected cells, when the cell is clicked... (If possible, I'd like these cells after the time appears to become unchangeable .....something like to be locked.)
        I do appreciate your time and thanx in advance
        Attila, Hungary
        exyzee@gmail.com
        • To post as a guest, your comment is unpublished.
          crystal · 3 years ago
          Dear Attila,
          Please try the below screenshot to insert the actual time to cell in a certian range when it is clicked.
          (The automatically locking cells function can't be acheived, sorry about that)

          Private Sub Worksheet_SelectionChange(ByVal Target As Range)
          Application.ScreenUpdating = False
          If Not Intersect(Target, Range("A1:B10")) Is Nothing Then
          Cancel = True
          Target.Formula = Date
          End If
          End Sub