Help with VBA UserForms simple math adding two textboxes (WIN7, Excel7)

ozzborn

Board Regular
Joined
Sep 14, 2011
Messages
84
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I am creating a userform that is pretty simple.

The form posts the current date, Name of an employee, start date and an end date for leave.

So it has
1 txtbox for the current date
2 ComboBox for employee drop down list of names
3 txtbox for start date
4. txtbox for end date

I would like without have to create another command button have the two date txtboxes subtract from each other and return the # of days taken to post in a flat database with the other information.

Here is my current code and it is work really good as it is now but it just posts current date, name, and the two days. I would like it to post the # of days too.

I found this code searching the web " TextBox3.Value = CDbl(TextBox1.Value) - CDbl(TextBox2.Value)". I have no idea where it shouuld go? I am super new to VBA,,,this is my first code.

Code:
Private Sub cmdAddData_Click()
Dim ws As Worksheet
Dim Addto As Range

Set ws = Sheet2
Set Addto = ws.Range("c65356").End(xlUp).Offset(1, 0)

With ws
Addto = txtDate.Value
Addto.Offset(0, 1).Value = cboName.Value
Addto.Offset(0, 2).Value = txtStart.Value
Addto.Offset(0, 3).Value = txtEnd.Value
End With

txtDate.Value = Format(Date, "Medium Date")
cboName.Value = ""
txtStart.Value = ""
txtEnd.Value = ""
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdView_Click()
Unload Me
Sheet2.Select
Sheet2.Range("A1").Select
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
txtDate.Value = Format(Date, "Medium Date")
Me.cboName.SetFocus

End Sub
 
Last edited by a moderator:
Thank you I appreciate the help and thanks for your recommendations. That would keep errors down.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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