Consulting

Results 1 to 8 of 8

Thread: adding date with double click

  1. #1
    VBAX Regular aoc's Avatar
    Joined
    Apr 2007
    Location
    Istanbul
    Posts
    90
    Location

    adding date with double click

    hi,

    how can I add the day and month like 29.03 when I double click any cell in column D ?

    regards

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    [VBA]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Selection.Count > 1 Then Exit Sub
    If Target.Column = 4 Then
    Target.NumberFormat = "dd/mm"
    Target.Value = Date
    Cancel = True
    End If
    End Sub[/VBA]Charlize

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Hi, format column D as custom and then dd.mm then add this to the worksheet code module:
    [VBA]
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("D")) Is Nothing Then
    Target.Value = Date
    Cancel = True
    End If
    End Sub
    [/VBA]Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Regular aoc's Avatar
    Joined
    Apr 2007
    Location
    Istanbul
    Posts
    90
    Location
    hi,

    charlize's and yours does not work, what is the problem ?

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Works fine for me!, post your workbok or example workbook!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Regular aoc's Avatar
    Joined
    Apr 2007
    Location
    Istanbul
    Posts
    90
    Location

    adding date with double click

    hi,

    please check the attached file.code is in module 4

    regards

  7. #7
    VBAX Regular aoc's Avatar
    Joined
    Apr 2007
    Location
    Istanbul
    Posts
    90
    Location
    hi,

    charlizes works.I changed the place of code.yours has format problem

    thanks

  8. #8
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Aoc, the code supplied by both myself and Charlize was to be placed in the Worksheet code module NOT a standard module as per our instructions!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •