MsgBox to display [hh]:mm

L

learner

Trying to finish up the macro with this message box

wtime=ActiveCell.Value
MsgBox("You worked for " & wtime & "Hrs:Min")

Cell where the value is taken from contains formula, is formatted as [hh]:mm
and is displayed right. But when I try to use the value in the message box, I
get something like 9.12435E-3.

It's gotta be simple but I can't figure it out.
Thank you
 
T

Tom Hutchins

Try this

wtime = ActiveCell.Value
MsgBox ("You worked for " & Format(wtime, "hh:mm") & " Hrs:Min")

The cell's format isn't part of the value you are storing in wtime, so you
have to format it in the messagebox also.

Hope this helps,

Hutch
 
P

Per Jessen

Hi

You have to format the timevalue:

wtime = ActiveCell.Value
MsgBox ("You worked for " & Format(wtime, "hh:mm") & " Hrs:Min")

Regards,
Per
 
M

Mike H

Hi,

Try this

hrs = WorksheetFunction.Text(ActiveCell.Value, "[hh]") & " Hours "
Mins = Minute(ActiveCell.Value) & " Mins"

MsgBox "You worked for " & hrs & Mins

Mike
 
L

learner

Thanks Tom, works perfect.

Tom Hutchins said:
Try this

wtime = ActiveCell.Value
MsgBox ("You worked for " & Format(wtime, "hh:mm") & " Hrs:Min")

The cell's format isn't part of the value you are storing in wtime, so you
have to format it in the messagebox also.

Hope this helps,

Hutch

learner said:
Trying to finish up the macro with this message box

wtime=ActiveCell.Value
MsgBox("You worked for " & wtime & "Hrs:Min")

Cell where the value is taken from contains formula, is formatted as [hh]:mm
and is displayed right. But when I try to use the value in the message box, I
get something like 9.12435E-3.

It's gotta be simple but I can't figure it out.
Thank you
 
L

learner

I appreciate Mike,

It worked too and it now looks better than what I had in mind.

Mike H said:
Hi,

Try this

hrs = WorksheetFunction.Text(ActiveCell.Value, "[hh]") & " Hours "
Mins = Minute(ActiveCell.Value) & " Mins"

MsgBox "You worked for " & hrs & Mins

Mike

learner said:
Trying to finish up the macro with this message box

wtime=ActiveCell.Value
MsgBox("You worked for " & wtime & "Hrs:Min")

Cell where the value is taken from contains formula, is formatted as [hh]:mm
and is displayed right. But when I try to use the value in the message box, I
get something like 9.12435E-3.

It's gotta be simple but I can't figure it out.
Thank you
 
R

Rick Rothstein

You will also want to use Mike's WorksheetFunction.Text method instead of
the Format function that others posted **if** there is any chance that the
total hours could be more than 24... the Format function does not support
the [hh] argument (that is, you can't use the square brackets with it) and
will "wrap" the hours back to 0 at the 24-hour mark.

--
Rick (MVP - Excel)


learner said:
I appreciate Mike,

It worked too and it now looks better than what I had in mind.

Mike H said:
Hi,

Try this

hrs = WorksheetFunction.Text(ActiveCell.Value, "[hh]") & " Hours "
Mins = Minute(ActiveCell.Value) & " Mins"

MsgBox "You worked for " & hrs & Mins

Mike

learner said:
Trying to finish up the macro with this message box

wtime=ActiveCell.Value
MsgBox("You worked for " & wtime & "Hrs:Min")

Cell where the value is taken from contains formula, is formatted as
[hh]:mm
and is displayed right. But when I try to use the value in the message
box, I
get something like 9.12435E-3.

It's gotta be simple but I can't figure it out.
Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top