Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
GUS GUS is offline
external usenet poster
 
Posts: 45
Default increase date by month

I want a macro to increase a date given from a text box
by month up to 20 times and put the last day of the date at cells.

For example txt1.value = 30/06/03
then a loop must be fired

for da=1 to 20

cells(da,1).value= ?????? (last day of then next month 31/07/2003)
etc

next da


and change also the year if the code pass the last day 31/12

Thanks in advance


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default increase date by month

Private Sub TextBox1_AfterUpdate()
Dim dtX As Date
Dim iX As Long

dtX = TextBox1.Text
dtX = DateAdd("m", 20, dtX)
iX = DateSerial(Year(dtX), Month(dtX) + 1, 1) - 1
dtX = iX
MsgBox dtX

End Sub

HTH,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default increase date by month

Gus,

Here's some code that does the basics

Dim da As Long
Dim myDate As Date
Dim newdate As Date

myDate = CDate(TextBox1.Value)
For da = 1 To 20
newdate = DateSerial(Year(myDate), Month(myDate) + 1, Day(myDate))
If Month(newdate) Month(myDate) + 1 Then
MsgBox "help!!"
Exit For
Else
myDate = newdate
End If
Next da

It also highlights a basic problem. If the date of 31/01/2003 is entered,
when you add 1 month to that it becomes the 31/02/03 or 03/03/03 (that's how
Excel handles dates!). So is this correct, or do you want to revert to the
01/03/03, i.e. the first of the following month, or 2w8/02/03, i.e. the last
of that next month? And then what do you do the following month when there
ared 31 again.

Also, why add them in a loop, why not just add 20 months in one swoopp
myDate = CDate(TextBox1.Value)
newdate = DateSerial(Year(myDate), Month(myDate) + 20, Day(myDate))
You still have a date problem, but only one, not 20.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"GUS" wrote in message
...
I want a macro to increase a date given from a text box
by month up to 20 times and put the last day of the date at cells.

For example txt1.value = 30/06/03
then a loop must be fired

for da=1 to 20

cells(da,1).value= ?????? (last day of then next month 31/07/2003)
etc

next da


and change also the year if the code pass the last day 31/12

Thanks in advance




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default increase date by month

A possible modification that should give you the date of the last day of
each month (as that is what I understood you to require).

Private Sub CommandButton1_Click()
Dim newDate As Date
Dim myDate As Date
Dim da As Long

myDate = CDate(TextBox1.Value)
For da = 1 To 20
newDate = DateSerial(Year(myDate), Month(myDate) + 2, 0)
Cells(da, 1).Value = newDate
myDate = newDate
Next da

End Sub


Worked fine for me.

--
Regards,
Tom Ogilvy




Bob Phillips wrote in message
...
Gus,

Here's some code that does the basics

Dim da As Long
Dim myDate As Date
Dim newdate As Date

myDate = CDate(TextBox1.Value)
For da = 1 To 20
newdate = DateSerial(Year(myDate), Month(myDate) + 1, Day(myDate))
If Month(newdate) Month(myDate) + 1 Then
MsgBox "help!!"
Exit For
Else
myDate = newdate
End If
Next da

It also highlights a basic problem. If the date of 31/01/2003 is entered,
when you add 1 month to that it becomes the 31/02/03 or 03/03/03 (that's

how
Excel handles dates!). So is this correct, or do you want to revert to the
01/03/03, i.e. the first of the following month, or 2w8/02/03, i.e. the

last
of that next month? And then what do you do the following month when there
ared 31 again.

Also, why add them in a loop, why not just add 20 months in one swoopp
myDate = CDate(TextBox1.Value)
newdate = DateSerial(Year(myDate), Month(myDate) + 20, Day(myDate))
You still have a date problem, but only one, not 20.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"GUS" wrote in message
...
I want a macro to increase a date given from a text box
by month up to 20 times and put the last day of the date at cells.

For example txt1.value = 30/06/03
then a loop must be fired

for da=1 to 20

cells(da,1).value= ?????? (last day of then next month

31/07/2003)
etc

next da


and change also the year if the code pass the last day 31/12

Thanks in advance






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
Increase cell value by 1 month Melissa Excel Discussion (Misc queries) 1 November 16th 09 04:49 AM
Increase a date by 1 month KRK New Users to Excel 8 April 6th 09 12:42 PM
Calculating Annual % Increase that occurs mid month AdmiralAJ Excel Worksheet Functions 8 March 13th 09 12:46 AM
Date arithmetic: adding 1 month to prior end of month date manxman Excel Worksheet Functions 2 July 14th 06 09:29 PM
Sort month/date/year data using month and date only SMW820 Excel Discussion (Misc queries) 6 June 22nd 06 05:14 PM


All times are GMT +1. The time now is 03:19 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"