Converting CSV Date with VBA

MojoJojo2023

New Member
Joined
Aug 7, 2023
Messages
9
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello all,

I have started receiving a csv file where the month is being presented (with General formatting) as:

202405

I need to convert the date to "May-24" but converting it to a date leaves me with "Feb-54".

Has anyone encountered this issue before? I'm trying to use a For... Loop to convert each cell in a range to this date format.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
202405 will obviously be translated to Feb 28, 2454
You can obtain the string May-24 using in your loop something like
VBA Code:
    myFDate = Format(DateSerial(Left(Cells(I, "A"), 4), Right(Cells(I, "A"), 2), 1), "mmm-yy"
This assumes I is the pointer to the row and the value to be converted is in column A, adapt to your situation

If you need a true date, omit Format and the format string and you will get May 1st, 2024

Try...
 
Upvote 0
Solution

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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