VBA double click event - derive date

sh1pley

Board Regular
Joined
Dec 22, 2006
Messages
160
Hi I am trying to write some code for a double click event. I have a sheet called "Calendar" that has all the dates in the year.

Cell A1 has the year
The months go across and the number dates go down.

In cell B7 there is the number 6 which corresponds to 06/01/2011

In the sheet "Diary", cell L2 I need to derive this date. I have used the following code which works if the number in the activecell is higher than 12 but swaps the days and months over if the value is between 01 and 12. I guess this has something to do with settings but is there a work around?

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim CellCol As Integer
CellCol = ActiveCell.Column - 1

Sheets("Diary").Range("L2") = ActiveCell.Value & "/" & CellCol & "/" & Sheets("Calendar").Range("A1")

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:

Code:
Sheets("Diary").Range("L2").Value = DateValue(ActiveCell.Value & "/" & CellCol & "/" & Sheets("Calendar").Range("A1").Value)
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

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