Time Format

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
163
Hi all,

I'm trying to format a cell to a specific time format. I have another workbook with the correct time format that I'm trying to replicate: The cell shows "16:00", and the formula bar shows "4:00:00 PM". When I go into that cell and look at the cell format being used, it shows "Custom" as the category and "h:mm" as the Type.

I have tried to replicate this in my code with:

VBA Code:
Range("S2").Select
Selection.NumberFormat = "h:mm:"

or even:

VBA Code:
Range("S2").Select
Selection.NumberFormat = "h:mm:ss: AM/PM"

I have not had any luck with either of these. It just ends up showing "16:00" in the formula bar, as opposed to the desired "4:00:00 PM"

Any other suggestions please?

Thanks.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Sorry, typo on the code, it's supposed to be as below, but still not working for me.

VBA Code:
Range("S2").Select
Selection.NumberFormat = "h:mm"

VBA Code:
Range("S2").Select
Selection.NumberFormat = "h:mm:ss AM/PM"
 
Upvote 0

Forum statistics

Threads
1,215,547
Messages
6,125,461
Members
449,228
Latest member
moaz_cma

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