keeping a custom format date

will1128

Board Regular
Joined
Aug 6, 2010
Messages
70
I have columns of various types which need different formats. I'm aware Excel treats dates as a number, but I have a column which has dates as custom type in the format "M/D/YYYY H:MM". If I find a cell like this I need to keep the date. I've used a case statement for the other formatting & it seems to work. How do I keep my custom date format?

<code>
For Each ws In ActiveWorkbook.Worksheets
For Each c In ws.UsedRange
Select Case c.value
Case 0, 1, 2
c.NumberFormat = "0"
Case c.value = "M/DD/YYYY H:MM"
c.value = c.value
Case Else
c.NumberFormat = "0.0"
End Select
Next c
Next ws
</code>
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try

Code:
For Each ws In ActiveWorkbook.Worksheets
For Each c In ws.UsedRange
    If IsDate(c.Value) Then
        c.NumberFormat = "M/DD/YYYY H:MM"
    Else
        Select Case c.Value
            Case 0, 1, 2: c.NumberFormat = "0"
            Case Else: c.NumberFormat = "0.0"
        End Select
    End If
Next c
Next ws
 
Upvote 0
Thank you.

I had tried using IsDate(c.value) = True, but that didn't work....why is the If statement necessary?
 
Upvote 0
As far as I know IsDate() is read only so you need a If statement to check its value.
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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