changing Date where date is after current Date

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,864
Office Version
  1. 2019
Platform
  1. Windows
I have a spreadsheet where the dates are all in column C. The dates should be inputted as dd/mm/yyyy for eg 10/08/2006. Sometimes the operator types in the date as 08/10/2006 which is after the todays (Current) date

I need VBA code that will covert dates after the current date in column C for eg 08/10/2006 to the correct date ie 10/08/2006.

I have set up the the formula =now() in cell A2


Your assistance will be most appreciated.

Howard
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Erdinç E. Karaçam

Board Regular
Joined
Sep 23, 2006
Messages
202
Hi,

To Sheet1's code page:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Columns(1).NumberFormat = "dd/mm/yyyy;@"
End Sub

This code will editing A column after any process on Sheet1.
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,864
Office Version
  1. 2019
Platform
  1. Windows
Hi Erdinc

Thec Code is not working. If the current date in A2 is 02/10/2006 and the date in C10 has been entered as 08/12/2006 instead if 12/08/2006, I would like VBA code to be set up that says if the date is after the currect date i.e 02/10/2006, then the date that was incorrectly inputted as mm/dd/yyyy i.e 08/12/2006 should be converted to dd/mm/yyy i.e 12/08/2006.

Your assistance will be most appreciated.

Howard
 

Erdinç E. Karaçam

Board Regular
Joined
Sep 23, 2006
Messages
202
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Format(Target.Value, "dd/mm/yyyy") > Format(Range("A1").Value, "dd/mm/yyyy") Then
        Target = Format(Target.Value, "dd/mm/yyyy")
    End If
    
End Sub

Actually i can not understand it , because my not enaugh English but, just try the code, then please tell me is it true.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,458
Messages
5,658,884
Members
418,475
Latest member
ExcelBeginner233

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
Top