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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,224,823
Messages
6,181,170
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