Error Converting Textbox Time entry to A Decimal

Ark68

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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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
 
Upvote 0
Solution
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!
 
Upvote 0
I'm glad that you are found this as solution.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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