Error Converting Textbox Time entry to A Decimal

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,038
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am getting a type mismatch converting a time entered into a userform textbox ('me.tb_s1_lwr') to its decimal equivalent.

Code:
Dim bkg_start as double
Dim slwr_time as double
bkg_start = CDbl(Me.tb_s1_lwr.Value)
slwr_time = bkg_date + bkg_start

The value of Me.tb_s1_lwr = "8:00 AM".

I tried CInt and CLng similarly with no change.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

EXCEL MAX

Well-known Member
Joined
Nov 11, 2020
Messages
508
Office Version
  1. 2016
Platform
  1. Windows
Hello Ark68,
try to use "TimeValue"...
VBA Code:
    Dim bkg_start As Double
    Dim bkg_date As Double
    Dim slwr_time As Double
    bkg_start = TimeValue(Me.tb_s1_lwr.Value)
    slwr_time = bkg_date + bkg_start
 
Solution

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,038
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thank you Excel Max. That was what I needed!!!
I'm going to have to remember that. I'm going to need it more frequently for sur!
 

EXCEL MAX

Well-known Member
Joined
Nov 11, 2020
Messages
508
Office Version
  1. 2016
Platform
  1. Windows
I'm glad that you are found this as solution.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,231
Messages
5,768,938
Members
425,506
Latest member
AndreaWorkPlace

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