We can use the datediff function with a user-form to quickly and easily calculate the difference between two dates in days, months and years.
Watch the video below:
Watch this video on YouTube.
Here’s the complete code for the command button that executes the datediff function and an easy method to populate the combo-box:
Private Sub CommandButton1_Click()
nextBlankRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
TextBox3.Value = DateDiff(“d”, (TextBox1.Text), (TextBox2.Text))
Cells(nextBlankRow, 1) = TextBox1.Value
Cells(nextBlankRow, 2) = TextBox2.Value
Cells(nextBlankRow, 3) = TextBox3.Value
Cells(nextBlankRow, 4) = ComboBox1.Value
Private Sub UserForm_Initialize()