How to calculate dates from one text box to another?

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
I have two textboxes on a userform one of them gets today’s date assigned when the form opens, at the same time I would like to have the other textbox add 60 days to the first textbox then apply the result to its self if you know what I mean?

I’ve tried all different ways but can’t get it to work!

Any Ideas will be much appreciated. :)

Thanks in advance

Ryan UK :wink:
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
Try: -
<pre>
Private Sub UserForm_Initialize()

Me.TextBox1.Value = Format(Date, "dd/mm/yy")
Me.TextBox2.Value = Format(Date + 60, "dd/mm/yy")

End Sub
</pre>
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
Thanks Mudface but I need it to calculate the date from the first textbox just in case the date is manually changed. I've tried the following but it doesn’t work because the value or text is dd/mmm/yyyy instead of the date serial! Obviously this will be in the change event of the first textbox and also in the userform active event.

Oh and by the way one is a ComboBoxes, sorry my error!!! :(

NsProdDateTxt.Value = Format(NsOrderDateCom.Value + 60, "dd/mmm/yyyy")

Any more suggestions?

Cheers

Ryan UK :)
This message was edited by razzandy on 2002-10-23 09:22
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
On 2002-10-23 09:20, razzandy wrote:
Thanks Mudface but I need it to calculate the date from the first textbox just in case the date is manually changed. I've tried the following but it doesn’t work because the value or text is dd/mmm/yyyy instead of the date serial! Obviously this will be in the change event of the first textbox and also in the userform active event.

Oh and by the way one is a ComboBoxes, sorry my error!!! :(

NsProdDateTxt.Value = Format(NsOrderDateCom.Value + 60, "dd/mmm/yyyy")

Any more suggestions?

Cheers

Ryan UK :)

Sorry, Ryan, I'm not quite with you.

Let's recap a bit- you have a combobox and a textbox. Presumably the combobox has a list of dates in it? When the combobox is changed or the form is initialised, you want the textbox to show the combobox's date + 60 days?
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

On 2002-10-23 09:37, Mudface wrote:
On 2002-10-23 09:20, razzandy wrote:
Thanks Mudface but I need it to calculate the date from the first textbox just in case the date is manually changed. I've tried the following but it doesn’t work because the value or text is dd/mmm/yyyy instead of the date serial! Obviously this will be in the change event of the first textbox and also in the userform active event.

Oh and by the way one is a ComboBoxes, sorry my error!!! :(

NsProdDateTxt.Value = Format(NsOrderDateCom.Value + 60, "dd/mmm/yyyy")

Any more suggestions?

Cheers

Ryan UK :)

Sorry, Ryan, I'm not quite with you.

Let's recap a bit- you have a combobox and a textbox. Presumably the combobox has a list of dates in it? When the combobox is changed or the form is initialised, you want the textbox to show the combobox's date + 60 days?

Sorry Mudface I'm even confusing myself now. :(

I used a comboBox as I was going to add search capabilities by date for my orders, but really I could just change it to a TextBox now. Anyway sticking with what I’ve got, as you say, I do want the textbox to show the combobox's date + 60 days when the comboBox changes or the form is initialised!

Many Thanks


Ryan UK :)
This message was edited by razzandy on 2002-10-23 09:53
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
:biggrin:.

Try this, I typed in a few dates in cells A1:A4 on a worksheet and set the combobox's RowSource property to that range and it seems to work OK, change the names of the combo and textbox's to suit-
<pre>
Private Sub ComboBox1_Change()

With ComboBox1
.Value = Format(.Value, "dd-mmm-yyyy")
TextBox1.Value = Format(CDate(.Value) + 60, "dd-mmm-yyyy")
End With

End Sub

Private Sub UserForm_Initialize()

With ComboBox1
.ListIndex = 0
.Value = Format(.Value, "dd-mmm-yyyy")
TextBox1.Value = Format(CDate(.Value) + 60, "dd-mmm-yyyy")
End With

End Sub
</pre>
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
Thanks Mudface

Thats just what I wanted.

You’ve triumphed again!! :wink:

Cheers
P.S I've not seen CDate b4!!
Ryan UK :)
 

Forum statistics

Threads
1,144,363
Messages
5,723,917
Members
422,527
Latest member
JayTheKaz

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
Top