VBA CODE TO CONVERT TO PROPER DATE

NeelsBorstlap

New Member
Joined
Jul 23, 2010
Messages
25
Hi

I get an excel file from 3rd party with the dates in a column like this:
Total Variable InsuranceFirst Instalment DateFinal Payment Due DateLast Receipt Date
0.0015/02/202115/02/202115/02/2021
0.0012/02/202112/02/202115/02/2021
0.0019/02/202119/04/202123/04/2021
0.0019/02/202119/02/202119/02/2021
I want to use VBA code that will convert the data in the columns with the dates info in it to look like this correct date format:

15-Jan-21
12-Jan-21
19-Jan-21
19-Jan-21

and another file from someone else with date in a column like this:
Inst.CycleInst. DtTrack.Amount
1Monthly2021/12/10 Fri7 Day3,167.55
1Monthly2021/12/11 Sat7 Day8,470.93
2Monthly2021/12/12 Sun7 Day3,370.61

I want to use VBA code that will convert the data in the columns with the dates info in it to look like this correct date format:
10-Jan-21
11-Jan-21
12-Jan-21

I am not good with code and most of the time only record the macro but can net get this to work.
Hope someone can help me.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You don't need vba for that, simply select your date cells then press Ctrl #
 
Upvote 0
Hi

So in your 1st example excel seems to recognise that its a date

so the below seems to work

VBA Code:
Columns("C:C").NumberFormat = "dd-mmm-yy"

However, in your second example excel does not recognise the date as a date, and the above only works if you remove the last 4 charracters from the cell.

Someone else may have another suggestion here, but a code could be written to remove these charracters perhaps, but the question is, are there any more scenarios where the data may look different.

Dave
 
Upvote 0
You don't need vba for that, simply select your date cells then press Ctrl #
Thanks for you reply.

Not sure what you mean by Ctrl+# - My # is the upper case of 3 - so must I press Ctrl+3 or Ctrl+shift+3

When I select the data and press ctrl+3 the only thing that happens is the format change to italic like this -
15/02/2021
 
Upvote 0
Not sure what you mean by Ctrl+# - My # is the upper case of 3 - so must I press Ctrl+3 or Ctrl+shift+3
It sounds like you have a US keyboard layout so yes, if it's the upper character on the key then you need to use shift as well.

Ctrl 3 simply toggles italic text on or off.
 
Upvote 0
Hi

So in your 1st example excel seems to recognise that its a date

so the below seems to work

VBA Code:
Columns("C:C").NumberFormat = "dd-mmm-yy"

However, in your second example excel does not recognise the date as a date, and the above only works if you remove the last 4 charracters from the cell.

Someone else may have another suggestion here, but a code could be written to remove these charracters perhaps, but the question is, are there any more scenarios where the data may look different.

Dave
Dave

Thanks for your reply but that code do not change the data to the proper date format like: from 19/02/2021 to 19-Feb-2021
 
Upvote 0
In that case your dates are most likely text strings and not real dates as they appear to be in the examples.

What is your default system date format? (the one that you see if you look at the clock in the bottom right corner of your screen).

I also need to know which columns the dates are in on each sheets.
 
Upvote 0
Dave

Thanks for your reply but that code do not change the data to the proper date format like: from 19/02/2021 to 19-Feb-2021
Strange. It did for me. But as I said only on your 1st example data set. Not the 2nd.
 
Upvote 0
Hi

Here is my data in a minisheet and what it must look like after the vba code is run.

Book2
ABCD
1BeforeAfterBeforeAfter
215/02/202115-Feb-212021/12/10 Fri10-Dec-21
312/02/202112-Feb-212021/12/10 Fri10-Dec-21
419/04/202119-Apr-212021/12/11 Sat11-Dec-21
519/02/202119-Feb-212021/12/10 Fri10-Dec-21
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,914
Members
449,132
Latest member
Rosie14

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