Convert days into the hours in Userform

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Good Morning

i have got a user form whereby it inputs the total number of days between the two dates selected from a calendar, however, i would like to convert this into the hours instead of the total days

VBA Code:
Sub Calculate_Days()
    Me.TextBox7 = ""
    
    If Me.TextBox2.Value <> "" And Me.TextBox3.Value <> "" Then 'textbox2 is the start date & textbox3 is the end date (end date is always greater than the start date
        If CDate(Me.TextBox3.Value) >= CDate(Me.TextBox2.Value) Then
            If Me.ComboBox2.Value = "HD" Then
                Me.TextBox7 = Format((CDate(Me.TextBox3.Value) - CDate(Me.TextBox2.Value) + 1) / 2, "0.0") 'Shows number of days in textbox7
            Else
                 Me.TextBox7 = Format(CDate(Me.TextBox3.Value) - CDate(Me.TextBox2.Value) + 1, "0")
                 Me.TextBox8 = Me.TextBox6.Value - Me.TextBox7.Value 'textbox8 minus the total number of days from textbox7
                 
            End If
        End If
    End If
       
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi,

There is a built-in function in Excel to Convert.
=CONVERT(yourDuration,"day","hr")

Hope this can help
 
Upvote 0
Morning James

sorry where do i record this? and where should change it?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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