Note: The other languages of the website are Google-translated. Back to English
Logáil isteach  \/ 
x
or
x
Cláraigh  \/ 
x

or

Conas dáta / am reatha a chur leis / a iontráil i gcill le cliceáil faoi dhó in Excel?

Más gá duit an dáta nó an dáta reatha a chur isteach go minic i mbileog oibre, is féidir leat an modh san alt seo a thriail. Cuideoidh an t-alt seo leat dáta nó dáta reatha a chur leis nó a iontráil go huathoibríoch i gcealla raon sonraithe gan ach cliceáil faoi dhó.

Cliceáil faoi dhó chun an dáta reatha nó an t-am dáta le cód VBA a chur leis / a iontráil


Cliceáil faoi dhó chun an dáta reatha nó an t-am dáta le cód VBA a chur leis / a iontráil


Féadfaidh tú an cód VBA thíos a rith chun dáta nó am reatha a chur go huathoibríoch i gcill le cliceáil dúbailte. Déan mar a leanas le do thoil.

1. Cliceáil ar dheis ar an táb Bileog ar mhaith leat an dáta reatha a chur isteach sna cealla sonraithe, ansin roghnaigh Féach an cód ón roghchlár cliceáil ar dheis.

2. Sa Microsoft Visual bunúsach d’Fheidhmchláir an cód VBA thíos a fhuinneog, a chóipeáil agus a ghreamú isteach i bhfuinneog an Chóid.

Cód VBA: Cliceáil faoi dhó chun an dáta reatha a chur i gcill

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

nótaí:

1. Sa chód, is é A1: B10 an raon a gcuirfidh tú an dáta reatha leis.
2. Más gá duit an t-am dáta reatha a chur leis an gcill, cuir ceann eile ina áit dáta le Anois () sa chód. Is féidir leat iad a athrú de réir mar is gá duit.

3. Brúigh Eile + Q eochracha ag an am céanna chun an Microsoft Visual Basic d’Fheidhmchláir fuinneog agus filleadh ar an mbileog oibre.

As seo amach, agus aon chill á chliceáil faoi dhó i raon sonraithe A1: B10. Iontrálfar an dáta nó an dáta reatha go huathoibríoch.


Earraí gaolmhara:


Na hUirlisí Táirgiúlachta Oifige is Fearr

Réitíonn Kutools for Excel an chuid is mó de do chuid Fadhbanna, agus Méadaíonn sé do Tháirgiúlacht 80%

  • Athúsáid: Cuir isteach go tapa foirmlí casta, cairteacha agus aon rud a d'úsáid tú roimhe seo; Cealla a Chriptiú le pasfhocal; Cruthaigh Liosta Ríomhphoist agus seol ríomhphoist ...
  • Barra Foirmle Super (cuir línte iolracha téacs agus foirmle in eagar go héasca); Leagan Amach Léitheoireachta (líon mór cealla a léamh agus a chur in eagar go héasca); Greamaigh go dtí an Raon Scagtha...
  • Cumaisc Cealla / Sraitheanna / Colúin gan Sonraí a chailleadh; Ábhar Cealla Scoilt; Comhcheangail Sraitheanna / Colúin Dúblacha... Cill Dúblach a Chosc; Déan comparáid idir Ranganna...
  • Roghnaigh Dúblach nó Uathúil Sraitheanna; Roghnaigh Blank Rows (tá na cealla uile folamh); Aimsigh Super agus Fuzzy Aimsigh i go leor Leabhar Oibre; Roghnaigh go randamach ...
  • Cóip Díreach Cealla Il gan tagairt fhoirmle a athrú; Tagairtí Cruthaigh Auto chuig Bileoga Il; Cuir Urchair isteach, Boscaí Seiceála agus go leor eile ...
  • Sliocht Téacs, Cuir Téacs leis, Bain de réir Poist, Bain Spás; Subtotals Paging a chruthú agus a phriontáil; Tiontaigh Idir Ábhar Cealla agus Tráchtanna...
  • Scagaire Super (scéimeanna scagaire a shábháil agus a chur i bhfeidhm ar bhileoga eile); Ard-Sórtáil de réir míosa / seachtaine / lae, minicíocht agus níos mó; Scagaire Speisialta le cló trom, iodálach ...
  • Comhcheangail Leabhair Oibre agus Bileoga Oibre; Cumaisc Táblaí bunaithe ar eochaircholúin; Roinn Sonraí i Ilbhileoga; Baisc Tiontaigh xls, xlsx agus PDF...
  • Níos mó ná 300 gné chumhachtach. Tacaíochtaí Office / Excel 2007-2019 agus 365. Tacaíonn sé le gach teanga. Imscaradh éasca i d’fhiontar nó d’eagraíocht. Gnéithe iomlána triail saor in aisce 30 lá. Ráthaíocht ar ais airgid 60 lá.
cluaisín kte 201905

Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
bun officetab
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 · 2 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 · 3 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 · 4 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 · 4 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 · 4 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