Formatting of Time in message box

Kentetsu

Well-known Member
Joined
Jan 22, 2004
Messages
520
Hi all,

So, I've got a message box that will pop up to tell the user what ingredient to add, and how long it will have to mix for. However, the time (which should be displayed as minutes, like 2:00) shows up as 8.333333333333E-2 (or something like that). I've checked the formatting of the cell that I am drawing the info from, and it appears correctly. Not sure how to change the formatting in a message box.

Code:
MsgBox "Your 2nd Ingredient(s) = " & Sheets("Scrap").Range("E15").Value _
    & " And Will Mix for " & Sheets("Scrap").Range("E16").Value & vbCrLf & vbCrLf & _
     "Add The Ingredient(s), THEN Click OK", vbOKOnly

Any advice is greatly appreciated...
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try:
Code:
Sub M1()


    Dim strMsg      As String
    Dim strTime     As String
    
    strMsg = "Your 2nd Ingredient(s) = @2ING@1@1And will mix for: @TIME@1@1Add the ingredient(s), THEN Click ok"
    
    With Sheets("Scrap")
        strTime = Format(.Cells(16, 5).Value, "MM:SS")
        
        strMsg = Replace(strMsg, "@2ING", .Cells(15, 5).Value)
        strMsg = Replace(strMsg, "@TIME", strTime)
        
        MsgBox Replace(strMsg, "@1", vbCrLf), vbOKOnly, "Second Ingredients"
    End With
        
End Sub
 
Last edited:
Upvote 0
Thanks JackDanIce, that definitely gets me closer.

Now the time (2:00) is being displayed as 12:00. I checked another part number with a different mix time (10:00), and that also displays as 12:00. Any thoughts on that?

Thanks again...
 
Upvote 0
I'm guessing it may be a difference between the value within the cell vs how the cell has been formatted.

What is the actual value in E16, how is it displayed and what is the cell formatting set to?
 
Upvote 0
The formatting of the cell is h:mm and it displays as 2:00, 10:00, etc.

The cell contains a Vlookup that returns the mix time, so maybe that's the problem?
 
Last edited:
Upvote 0
If the cell formatting is h:mm, then 2:00 I believe is the conversion of the value in the cell displayed as hours and minutes so that's 2 hours of time rather than 2 minutes.

Try using either line in blue (not both in the same procedure):
Rich (BB code):
Sub M1()


    Dim strMsg      As String
    Dim strTime     As String
    
    strMsg = "Your 2nd Ingredient(s) = @2ING@1@1And will mix for: @TIME@1@1Add the ingredient(s), THEN Click ok"
    
    With Sheets("Scrap")
        
        strTime = Format(.Cells(16, 5), "MM:SS")
        strTime = .Cells(16, 5).Text
        
        strMsg = Replace(strMsg, "@2ING", .Cells(15, 5).Value)
        strMsg = Replace(strMsg, "@TIME", strTime)
        
        MsgBox Replace(strMsg, "@1", vbCrLf), vbOKOnly, "Second Ingredients"
    End With
        
End Sub
I'm guessing you know how to comment code so can comment out each blue line in turn as you test the code...
 
Last edited:
Upvote 0
Hm, to keep things simple I attempted to reuse strTime as the value for Application.wait But, I'm getting a type mismatch error when it hits Application.wait

Rich (BB code):
strMsg = _
"Your 1st Ingredient(s) = @2ING@1@1And will mix for: @time Minutes.  @1@1 Add the ingredient(s), THEN Click OK to Begin Timing"

With Sheets("Scrap")
        strTime = .Cells(14, 5).Text
        strMsg = Replace(strMsg, "@2ING", .Cells(13, 5).Value)
        strMsg = Replace(strMsg,  @time", strTime)
        MsgBox Replace(strMsg, "@1", vbCrLf), vbOKOnly, "First Ingredient(s)"
    End With
    
Sheets("Stop").Visible = True
Sheets("Go").Visible = xlVeryHidden
    
Application.Wait (Now + TimeValue(strTime))

Sheets("Go").Visible = True
Sheets("Stop").Visible = xlVeryHidden
 
Upvote 0
I'm guessing because strTime is a string variable and TimeValue requires a time or at least numerical variable?
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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