Error Converting Textbox Time entry to A Decimal

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,980
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

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
3,980
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.
 

Forum statistics

Threads
1,148,364
Messages
5,746,276
Members
424,003
Latest member
paaskanama

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