Date formatting

vbaNewby

Board Regular
Joined
Jan 26, 2011
Messages
138
Hi guru's!

I have two cells that look like the following:

Cell A1: Jan 1, 11
Cell A2: Feb 2, 11

In VBA, I need to reformat these so they look like this.

Cell A1: 1/1/2011
Cell A2: 2/2/2011

The purpose behind this is so that I can use datediff in the correct format.

Is there an easy way to change up this date format?

Thanks in advance.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If they are dates rather than text that looks like dates, DateDiff doesn't care what the formats are.
 
Upvote 0
You could just select the column and do Data > Text to columns, Finish.

If you want to do it in code,

Code:
    Dim cell        As Range
 
    For Each cell In Range("A1:A2")
        If IsDate(cell.Text) Then
            cell.Value = CDate(cell.Text)
            cell.NumberFormat = "m/d/yy"
        End If
    Next cell
 
Upvote 0
You could just select the column and do Data > Text to columns, Finish.

If you want to do it in code,

Code:
    Dim cell        As Range
 
    For Each cell In Range("A1:A2")
        If IsDate(cell.Text) Then
            cell.Value = CDate(cell.Text)
            cell.NumberFormat = "m/d/yy"
        End If
    Next cell
Thanks for the help shg4421!
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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