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
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,096
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
Can you post the code for Trial?
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,918
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,281
Messages
5,600,705
Members
414,401
Latest member
grenona2020

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
Top