Userform Option Button if True assigns current time

EmmatheDancer

New Member
Joined
Sep 20, 2014
Messages
11
Hi,

I have set up a userform which has several option buttons one of which I want, when selected to assign the current time in the format "hh:mm" to TimeMax. For some reason when I get a msgbox to display TimeMax it prints 00:00:00? Does anyone know how to do this?

Below is the code for the userform:

Code:
Private Sub Cancel_Click()
    Unload Me
End Sub

Private Sub OK_Click()
   Dim TimeMax As Date
 
   Select Case True
      Case Now
         TimeMax = Format(Now, "hh:mm")
      Case Ten
         TimeMax = "10:15"
      Case Twelve
         TimeMax = "12:15"
      Case Two
         TimeMax = "14:15"
      Case Four
         TimeMax = "16:15"
   End Select
 
   Unload Me
   Call Trial(TimeMax)

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi
A variable will contain the complete data, formatting is just a mask. Note that on the example below, the two message boxes are using the same variable:

Code:
Sub Emma()
Dim timemax As Date
timemax = TimeValue("16:15:38") + 30000
MsgBox Format(timemax, "[$-409]d/m/yy h:mm AM/PM;@"), 64, "Complete format"
MsgBox Format(timemax, "hh:mm"), 64, "Simple format"
End Sub
 
Upvote 0
Can you post the code for Trial?
 
Upvote 0
It looks like the variable TimeMax is scoped to the procedure. After the Userform is unloaded, I'm not sure what it will do. Try

Code:
    Me.Hide
    Call Trial(TimeMax)
    UnLoad Me
 
Upvote 0

Forum statistics

Threads
1,213,537
Messages
6,114,216
Members
448,554
Latest member
Gleisner2

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