problem function date add into datepicker on userform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hi
i have problem add years and months days is ok i have textbox1= days textbox2= months textbox3= years when i choose in datepicker1= date then add months an years to datepicker2
this is my simple code
VBA Code:
Private Sub CommandButton2_Click()
    datepicker2 = DateAdd("d", textbox1.Text, datepicker1)
     datepicker2 = DateAdd("M", textbox2.Text, datepicker1)
      datepicker2 = DateAdd("YYYY", textbox3.Text, datepicker1)
End Sub


1.JPG
 
Sorry, the correct code is this:

VBA Code:
Private Sub CommandButton1_Click()
'Account OLD
  TextBox3.Value = CDate(TextBox2.Value) - CDate(TextBox1.Value)
End Sub

Private Sub CommandButton2_Click()
'Account Date
  datepicker2 = datepicker1 + (CDate(TextBox2.Value) - CDate(TextBox1.Value))
End Sub

1590425422494.png
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Any system for counting years and months will inevitably have differences due to the variable length of months.
In my opinion, it is impossible to get a completely "accurate" result by measuring date differences in this way.
I recommend you only get a textbox (3) to get the total days.
Delete textbox 4 and 5,
I agree !!!
 
Upvote 0
thanks your both Dante,Rick it's better than before i would thank you for every all your support and i apology if my subject not clear from the beginning it takes more time to solve me problem this is because of me don't make clear from the beginning more again thanks for your patience and time
god bless you
 
Upvote 0
Cross posted with no links yet again. :(

Please supply the link(s).
 
Upvote 0
I don't care where you posted first, WHENEVER you cross post you MUST supply the link(s).
 
Upvote 0
but as far as i know when you ask the link to don't waste time the members if the post solved in specific forum and don't inform the members about the solve , right ?
 
Upvote 0
WRONG. You need to supply link(s) WHENEVER you cross post. Not just when you feel like it.
You have already been directed to this site on more then one occasion. I would suggest you read it.
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

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