Not Date Formats Converting

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
Any idea why this code isn't converting all dates in the ranges to MM/DD/YY? It does change some of the dates, but not all. The ones that aren't being changed show values like 07/17/2023 in the formula bar. If I double click in a cell that wasn't converted, the date magically converts.

VBA Code:
'Format columns as MM/DD/YY.
mD.Range("G2:G" & mDLR).NumberFormat = "MM/DD/YY"
mD.Range("K2:K" & mDLR).NumberFormat = "MM/DD/YY"
mD.Range("M2:M" & mDLR).NumberFormat = "MM/DD/YY"
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Date formats only work on numbers/values entered as valid dates.
It does NOT work on values that were entered as Text (formatting does not apply to any Text entries).

If you re-enter it, it usually converts it to a date which can be formatted (provided it is a valid date value, and not something like 02/32/2023).
You can re-enter/convert a whole column at a time by selecting the column, going to "Text to Columns" from the Data menu, going to the third step, and select the Date option with the MDY format, and clicking finish.
You will have to do each column individually, as you cannot do Text to Columns on more than one range at a time.
 
Upvote 0
Solution
Date formats only work on numbers/values entered as valid dates.
It does NOT work on values that were entered as Text (formatting does not apply to any Text entries).

If you re-enter it, it usually converts it to a date which can be formatted (provided it is a valid date value, and not something like 02/32/2023).
You can re-enter/convert a whole column at a time by selecting the column, going to "Text to Columns" from the Data menu, going to the third step, and select the Date option with the MDY format, and clicking finish.
You will have to do each column individually, as you cannot do Text to Columns on more than one range at a time.
Didn't even think about the data coming over as text. Thanks @Joe4
 
Upvote 0
You are welcome.
That is usually the dead give-away. Formatting has no impact on text entries.
Also, if you notice that the dates (or numbers) are left-justified in a cell instead of right-justified, that is also another indication you are working with text entries.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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