#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Time format

On my spreadsheet, cell "A1" shows the time of "9:50 PM".
However, when I run the following code:

MsgBox Range("A1").Value

the message box shows a time of "0.9097222222".

How do i fix this so it shows "9:50 PM" in the MessageBox?

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 12:28:25 -0700 schrieb Robert Crandal:

On my spreadsheet, cell "A1" shows the time of "9:50 PM".
However, when I run the following code:

MsgBox Range("A1").Value

the message box shows a time of "0.9097222222".

How do i fix this so it shows "9:50 PM" in the MessageBox?


try:
MsgBox Format([A1], "h:mm AM/PM")


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 21:32:45 +0200 schrieb Claus Busch:

MsgBox Format([A1], "h:mm AM/PM")


or:
MsgBox [A1].Text


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Time format

"Claus Busch" wrote in

try:
MsgBox Format([A1], "h:mm AM/PM")


Thanks Claus. That code above did work great.

However, I found code in my project that does NOT
use Range("A1"). For example, a lot of my code
looks like this:

Sheets(i).Cells(n, 22).Value ' has a time value

I tried changing this code to:

Sheets(i).Cells(n, 22).Text

.....but that didn't work. What do I need to do with
this code that uses Sheets() rather than Range()??


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 12:48:02 -0700 schrieb Robert Crandal:

Sheets(i).Cells(n, 22).Value ' has a time value

I tried changing this code to:

Sheets(i).Cells(n, 22).Text


what do you want to do?
For me MsgBox Sheets(i).Cells(n, 22).Text
will work


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 21:56:12 +0200 schrieb Claus Busch:

what do you want to do?
For me MsgBox Sheets(i).Cells(n, 22).Text
will work


if you want to insert a time in sheets(i).cells(n,22) then try:
Sheets(i).Cells(n, 22) = Format(TimeValue("09:15:00"), "h:mm AM/PM")


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default Time format

"Claus Busch" wrote in message
...

what do you want to do?
For me MsgBox Sheets(i).Cells(n, 22).Text
will work


Now I know what went wrong. The cell that holds
a time value is protected as "hidden". Ugh, does that
mean I need to write code that temporarily removes
the "hidden" property?



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 13:04:47 -0700 schrieb Robert Crandal:

"Claus Busch" wrote in message
...

what do you want to do?
For me MsgBox Sheets(i).Cells(n, 22).Text
will work


Now I know what went wrong. The cell that holds
a time value is protected as "hidden". Ugh, does that
mean I need to write code that temporarily removes
the "hidden" property?



Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Time format

Hi Robert,

Am Mon, 29 Apr 2013 13:04:47 -0700 schrieb Robert Crandal:

Now I know what went wrong. The cell that holds
a time value is protected as "hidden". Ugh, does that
mean I need to write code that temporarily removes
the "hidden" property?


only the formula is hidden. The value or the text you can show with a
MsgBox


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 4 February 13th 09 04:34 PM
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 1 February 13th 09 01:37 AM
How to format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 0 February 13th 09 12:49 AM
How to type format time in decimal format & calculate time Cheyenne Excel Discussion (Misc queries) 1 February 13th 09 12:09 AM
Remove time from a date and time field? Format removes the displa. oaoboc Excel Worksheet Functions 1 February 16th 05 07:20 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"