Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Subtracting Dates in TextBoxes

Anyone have an idea how to do the following:

On a UserForm.
TextBox1 = 9/20/04
TextBox2 = 9/28/04

Once the date is entered into TextBox2, TextBox 3 should populate with:
"1 week & 2 days"

Thanks,
John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Subtracting Dates in TextBoxes

John,

Here's a start. It doesn't check to make sure date1 is earlier than date2.
It also starts filling in box3 before the second date is completely entered
because I used a Change event. An Exit event would only work if you left
one of the textboxes which seems worse to me. Anyways, enter this code into
the UserForm, or just wait for one of the many really smart people in this
group to follow up with a more complete answer:

Private Sub TextBox1_Change()
Call date_change
End Sub

Private Sub TextBox2_Change()
Call date_change
End Sub

Sub date_change()
Dim dif As Long

If IsDate(Me.TextBox1) And IsDate(Me.TextBox2) Then
dif = CDate(Me.TextBox2) - CDate(Me.TextBox1) + 1
Me.TextBox3 = Int((dif) / 7) & " weeks " _
& dif Mod 7 & " days"
End If
End Sub

hth,

Doug Glancy

"John Wilson" wrote in message
...
Anyone have an idea how to do the following:

On a UserForm.
TextBox1 = 9/20/04
TextBox2 = 9/28/04

Once the date is entered into TextBox2, TextBox 3 should populate with:
"1 week & 2 days"

Thanks,
John




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Subtracting Dates in TextBoxes

Textbox3.Text = CDate(Textbox2.Text) - CDate(Textbox1.Text)

will give you 8. You can work out how to turn that into weeks and days,
especially as you get 9?

--

HTH

RP

"John Wilson" wrote in message
...
Anyone have an idea how to do the following:

On a UserForm.
TextBox1 = 9/20/04
TextBox2 = 9/28/04

Once the date is entered into TextBox2, TextBox 3 should populate with:
"1 week & 2 days"

Thanks,
John




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Subtracting Dates in TextBoxes

Thanks guys.....

CDate was the "key" that I was missing.
Brain fart, I guess?

Thanks again,
John

"Bob Phillips" wrote in message
...
Textbox3.Text = CDate(Textbox2.Text) - CDate(Textbox1.Text)

will give you 8. You can work out how to turn that into weeks and days,
especially as you get 9?

--

HTH

RP

"John Wilson" wrote in message
...
Anyone have an idea how to do the following:

On a UserForm.
TextBox1 = 9/20/04
TextBox2 = 9/28/04

Once the date is entered into TextBox2, TextBox 3 should populate with:
"1 week & 2 days"

Thanks,
John






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtracting Dates Dilly Excel Discussion (Misc queries) 10 January 28th 08 04:00 PM
Subtracting Dates jaxstraww Excel Discussion (Misc queries) 0 March 28th 07 01:56 AM
Subtracting Dates BoniM Excel Discussion (Misc queries) 0 March 28th 07 12:17 AM
Subtracting Dates sam Excel Discussion (Misc queries) 3 March 2nd 06 12:47 PM
Dates in TextBoxes James[_25_] Excel Programming 3 July 15th 04 01:53 PM


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"