Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Time format in formula bar not changing

0

I have inherited a large spreadsheet with multiple columns with start and end times that stretch over a period of weeks for multiple rows.  Columns with the time in 24 hour format display as expected in their cells, for example 14:00, 18:00. 09:00.  In the formula bar they appear in different formats 14:00, 6:00:00pm, 09:00.  I have attempted to reformat the cells using different time formats but the format in the formula bar does not change.  Only by manually over writing the cell does the format change from 09:00 to 9:00:00am.  This in itself is not a problem but when I attempt to run a formula to determine the earliest start time and the latest end time for each day the results are not correct.

Answer
Discuss

Answers

0

Hello n180093,

The difference you are seeing all comes down to cell formatting. What is displayed in the formula bar is how the data was entered into the cell. What is displayed in the cell is detemined by the cell formatting.

In your sample file cell, "D4" is formatted as "General", so what is displayed in the formula bar and cell are the same. Cell "D5" is formatted as "Custom" (h:mm) so the formula bar displays what was entered (8:00:00 PM) and the cell displays that as per the formatting (20:00)

When working with time values the cell values must all be in the same time format; using a general format will not give the desired results. Make sure all of the cells are using the same custom format and you calculations should work out.

Cheers   :-)

Discuss

Discussion

Looks liked I messed up with the extract I did of my file.  I did not have the correct formating in place.  I have since uploaded the corrected file.   Please have a look if you have time.  Thanks
n180093 Oct 16, '23 at 2:20 pm
@Willie - don't hold you breathe on this one. Seems the user liked my alternative answer but forgot to mark it as Selected (even though the conversion "fix" probably saved them a fair chunk of time). Oh um!
John_Ru (rep: 6377) Oct 17, '23 at 2:47 pm
Add to Discussion
0

n180093

Your revised file shows that the issue isn't the cell format (how Excel displays the values) but the values themselves.

By this I mean that Excel stores times as a number so, for example, 0.5 equates to midday (12:00 on the 24 hour clock). If I run a small macro to show what's in cells B4:B13, the results are (address then value, format):

  • B4: Value: 0.583333333333333 Cell Format= h:mm
  • B5: Value: 0.75 Cell Format= h:mm
  • B6: Value: 0.916666666666667 Cell Format= h:mm
  • B7: Value: 10:00 Cell Format= h:mm
  • B8: Value: 16:00 Cell Format= h:mm
  • B9: Value: 12:00 Cell Format= h:mm
  • B10: Value: 19:00 Cell Format= h:mm
  • B11: Value: 0.5 Cell Format= h:mm
  • B12: Value: 12:00 Cell Format= h:mm
  • B13: Value: 12:00 Cell Format= h:mm

and you can see that although they're all set to display as h:mm, only B4:B6 and B11 contain numbers, the rest are (presumably created or imported) as text. Therefore those cells won't work in numerical calculations. Specifically the MIN and LARGE functions will NOT see those cells until you change and enter them (and Excel see them as number). E.g.  change B10 from formula bar 19:00 to 09:00 and the formula bar will show subsequently show as 19:00:00 (hh:mm:ss) and appear as the MIN.

Your "overwritten" values ARE numbers, so the same macro gives numbers against all cells:

  • H4: Value: 0.583333333333333 Cell Format= h:mm
  • H5: Value: 0.75 Cell Format= h:mm
  • H6: Value: 0.916666666666667 Cell Format= h:mm
  • H7: Value: 0.416666666666667 Cell Format= h:mm
  • H8: Value: 0.666666666666667 Cell Format= h:mm
  • H9: Value: 0.5 Cell Format= h:mm
  • H10: Value: 0.791666666666667 Cell Format= h:mm
  • H11: Value: 0.5 Cell Format= h:mm
  • H12: Value: 0.5 Cell Format= h:mm
  • H13: Value: 0.5 Cell Format= h:mm

One easy way to fix those text values is to put this is F4

=1*B4

then drag or copy it down to F13. Now select F4:F13, copy then select B4 and ribbon Home/ Paste (down) Paste Values/ Values(V).

B4:B13 will now be times so you can clear F4:F13. Likewise for your larger sheet.

Hope this helps. If so, please remember to mark this Answer as Selected.

Discuss

Discussion

That works, thanks so much.
n180093 Oct 17, '23 at 9:51 am
Glad that worked but you forgot the mark the Answer as Selected. Please do so (since that's all I get for helping you!)
John_Ru (rep: 6377) Oct 17, '23 at 10:14 am
Please respond to my message above
John_Ru (rep: 6377) Oct 18, '23 at 6:31 am
I guess you've forgotten about my help and my request above. Oh hum! 
John_Ru (rep: 6377) Nov 24, '23 at 3:06 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login