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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

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