Ga naar hoofdinhoud

Hoe automatisch de huidige datum / tijd in een cel toevoegen / invoeren door te dubbelklikken in Excel?

Als u de huidige datum of datum-tijd regelmatig in een werkblad moet invoegen, kunt u de methode in dit artikel proberen. Dit artikel helpt u om automatisch de huidige datum of datumtand toe te voegen of in te voeren in een opgegeven bereikcellen door alleen te dubbelklikken.

Dubbelklik om automatisch de huidige datum of datumtijd toe te voegen / in te voeren met VBA-code


Dubbelklik om automatisch de huidige datum of datumtijd toe te voegen / in te voeren met VBA-code

U kunt de onderstaande VBA-code uitvoeren om automatisch de huidige datum of datumtijd in een cel toe te voegen door te dubbelklikken. Ga als volgt te werk.

1. Klik met de rechtermuisknop op het tabblad Blad waarvan u de huidige datum in de opgegeven cellen wilt invoegen, en selecteer Bekijk code vanuit het rechtsklikmenu.

2. In de Microsoft Visual Basic voor toepassingen -venster, kopieer en plak de onderstaande VBA-code in het codevenster.

VBA-code: dubbelklik om de huidige datum aan een cel toe te voegen

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

Opmerkingen:

1. In de code is A1: B10 het bereik waaraan u de huidige datum wilt toevoegen.
2. Als u de huidige datum en tijd in de cel moet toevoegen, vervangt u Datum Met Nu() in de code. U kunt ze naar behoefte wijzigen.

3. druk op anders + Q toetsen tegelijk om het Microsoft Visual Basic voor toepassingen venster en keer terug naar het werkblad.

Vanaf nu, wanneer u dubbelklikt op een cel in het opgegeven bereik A1: B10. De huidige datum of tijd wordt automatisch ingevoerd.


Gerelateerde artikelen:

Beste Office-productiviteitstools

馃 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar effici毛ntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
Comments (30)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello. How do I enter the code so I can insert the date in a cell and the time in the adjacent row?
This comment was minimized by the moderator on the site
Holy crap MS get with it! Google sheets can make this happen with a couple of clicks.
This comment was minimized by the moderator on the site
Hi all,

I try to use that macro to use the date stamp double clicking on column E and it's working but when I try to replicate the macro to do the same but for the current time on column F it is not working as you can see attached I have an error message stating : Ambiguous Name Detected.
When I try to change the Sub WorkSheet part for another name and double click in the cells nothing happens.

Could someone help me on that ?

My code :


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

Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F1:F10000")) Is Nothing Then
Cancel = True
Target.Formula = Now()
End If
End Sub
This comment was minimized by the moderator on the site
Hi Louis,
Replicate the macro will cause two same procedures with the same name in a single sheet code window. Excel doesn't allow two or more same names of functions in a module. Not even in Events. It leads to ambiguity.
If you want to do a different task on the same event, you need to modify the original code to meet your needs.
The following VBA code can do you a favor. Please give it a try.
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updated by Extendoffice 20221025
    If Not Intersect(Target, Range("E1:E10000")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
    End If
    If Not Intersect(Target, Range("F1:F10000")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
    End If
End Sub
This comment was minimized by the moderator on the site
This function did not work. Double Clicking simply enters manual edit of cell.
This comment was minimized by the moderator on the site
Hi Bob,
The code works well in my case. I need to know more specific about your issue, such as your Excel version.
And the code only works on the cells you specified.
This comment was minimized by the moderator on the site
Hello there, the code did a lot for me, How can I restrict the code to work only if field is blank. If a date is already there in the cell, double click should do nothing, regards
This comment was minimized by the moderator on the site
Hi Ahmad,
Sorry for the trouble. To only fill in the blank cells with dates with double-clicking, you can apply the following VBA code to get it done.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updated by Extendoffice 20220609
    If Not Intersect(Target, Range("B1:C20")) Is Nothing Then
        If Target.Value = "" Then
            Cancel = True
            Target.Formula = Date
        End If
    End If
End Sub
This comment was minimized by the moderator on the site
This was just what I was looking for - this save a ton of time and I appreciate the well written instructions. Thank you!
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Hi Dylan,
Sorry can't help you with that yet. Thank you for your comment.
This comment was minimized by the moderator on the site
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.
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