Format question for double click = enter date to active cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Afternoon.
As per title.
When i double click a cell within the range mentioned in my code it should enter todays date.

The code below works fine apart from how the format date is entered.
So today its entered as 3/25/2019 but i would like to to be formatted & entered as 25/03/


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

Could you advise please.
Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Excel has a built in shortcut for that if you werent aware. Press CTRL then ;
 
Upvote 0
Afternoon.
As per title.
When i double click a cell within the range mentioned in my code it should enter todays date.

The code below works fine apart from how the format date is entered.
So today its entered as 3/25/2019 but i would like to to be formatted & entered as 25/03/


Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)    If Not Intersect(Target, Range("A5:A28")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
        [B][COLOR="#FF0000"]Target.NumberFormat = "dd/mm/yyyy"[/COLOR][/B]
    End If
End Sub

Could you advise please.
Thanks
Try adding the code line I show in red above and see if that makes the code do what you want.
 
Upvote 0
How about

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A5:A28")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
[COLOR=#0000ff]        Target.NumberFormat = "dd/mm/yyyy"[/COLOR]
    End If
End Sub
 
Upvote 0
OK
At first it made no difference but then i remember that column is formatted as Text.

Now that i have formatted that column to Date it works.

So i will need to keep an eye on it to see / remember why it was formatted as Text .

many thanks
 
Upvote 0
Morning,
Following on from above.

The current code in use is supplied below.
This months new worksheet in column A is formatted as DATE

I can double click in any cell in column A and as opposed to me now seeing 01/04/2019 i actually see 04/01/2019

This is what i was talking about in post #6 above

So as a test in the code below i changeds this dd/mm/yyyy to mm/dd/yyyy and now i see 01/04/2019

If i change it back to dd/mm/yyyy then i see 04/01/2019

** Even if i manually type 01/04/2019 it then automatically changes itself to 04/01/2019 **

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)    If Not Intersect(Target, Range("A4:A28")) Is Nothing Then
        Cancel = True
        Target.Formula = Date
        Target.NumberFormat = "dd/mm/yyyy"
    End If
End Sub
 
Last edited:
Upvote 0
If you format the date to general then you should see 43556 on the 1st of April 2019. If you dont try using CDate(Date).
 
Upvote 0
I didnt see 43556

Regarding you advise on CDate(Date) is the below correct as i still see it entered as 04/01/2019 when dd/mm/yyyy is in the code.
What should column A be formatted as or dont that make any difference ?

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)    If Not Intersect(Target, Range("A4:A28")) Is Nothing Then
        Cancel = True
        Target.Formula = CDate(Date)
        Target.NumberFormat = "dd/mm/yyyy"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top