changing Date where date is after current Date

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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.
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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