Weeks + date calculations in vba

winram05

New Member
Joined
Jun 29, 2017
Messages
6
Hi,

I am creating excel database (input via Userform) where i am facing two issues. could someone help me on below:


1. I am entering data through form and it is saving in sheet2 . The data contains numbers, date, text etc. But the numbers are saving in text format which is difficult for excel calculations.

2. Day + weeks = Day (example: 06/29/2017 (any day) + 2 weeks (14 days) = 07/13/2017)

in form, there is date picker and combo box to select the weeks. if we select date and weeks then in text box it should display the expected date (07/13/2017)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
When you use CDate(textbox.value) it will convert the value to a date value (instead of a text value.) For my example, TextBox1 is the entered date, ComboBox1 is the number of weeks, and TextBox2 is the new date to send to the worksheet.

Code:
Private Sub ComboBox1_Change()
n = ComboBox1
TextBox2 = Format(CDate(TextBox1) + 7 * n, "mm/dd/yyyy")
End Sub


Private Sub CommandButton1_Click()
Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1) = CDate(TextBox2)
End Sub


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim n%
n = ComboBox1
TextBox1 = Format(TextBox1, "mm/dd/yyyy")
TextBox2 = Format(CDate(TextBox1) + 7 * n, "mm/dd/yyyy")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,745
Members
449,116
Latest member
alexlomt

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