Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Do Until Loop

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Do Until Loop

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

  #3   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Do Until Loop

Yes that works very well. Thank you.

Can we please add one more parameter I also have an End Date so whichever
ends first either the range or the End Date

i.e. Start Date 1 Jan 08, End Date 31 Dec 10 and range to write this is 100
rows
if increments are monthly I need only 36 rows and thats where it should stop.

thanks/sgl

"Jacob Skaria" wrote:

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Do Until Loop

You can do that.. Please try this

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp <= dtEnd Then Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

Yes that works very well. Thank you.

Can we please add one more parameter I also have an End Date so whichever
ends first either the range or the End Date

i.e. Start Date 1 Jan 08, End Date 31 Dec 10 and range to write this is 100
rows
if increments are monthly I need only 36 rows and thats where it should stop.

thanks/sgl

"Jacob Skaria" wrote:

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Do Until Loop

A small modification to exit the loop when it reach end date

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp dtEnd Then Exit Do
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

You can do that.. Please try this

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp <= dtEnd Then Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

Yes that works very well. Thank you.

Can we please add one more parameter I also have an End Date so whichever
ends first either the range or the End Date

i.e. Start Date 1 Jan 08, End Date 31 Dec 10 and range to write this is 100
rows
if increments are monthly I need only 36 rows and thats where it should stop.

thanks/sgl

"Jacob Skaria" wrote:

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl



  #6   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Do Until Loop

Yes that worked very well thank you vm/sgl

"Jacob Skaria" wrote:

A small modification to exit the loop when it reach end date

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp dtEnd Then Exit Do
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

You can do that.. Please try this

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp <= dtEnd Then Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

Yes that works very well. Thank you.

Can we please add one more parameter I also have an End Date so whichever
ends first either the range or the End Date

i.e. Start Date 1 Jan 08, End Date 31 Dec 10 and range to write this is 100
rows
if increments are monthly I need only 36 rows and thats where it should stop.

thanks/sgl

"Jacob Skaria" wrote:

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Do Until Loop

Cheers !!!!

If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

Yes that worked very well thank you vm/sgl

"Jacob Skaria" wrote:

A small modification to exit the loop when it reach end date

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp dtEnd Then Exit Do
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

You can do that.. Please try this

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtEnd As Date
Dim dtTemp As Date

dtStart = "01/01/2008"
dtEnd = "12/31/2010"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
If dtTemp <= dtEnd Then Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

Yes that works very well. Thank you.

Can we please add one more parameter I also have an End Date so whichever
ends first either the range or the End Date

i.e. Start Date 1 Jan 08, End Date 31 Dec 10 and range to write this is 100
rows
if increments are monthly I need only 36 rows and thats where it should stop.

thanks/sgl

"Jacob Skaria" wrote:

Edit the dtStart to suit your requirement. For more about first argument
passed to DATEADD() functionality please refer below

Sub WriteDates()

Dim lngRow As Long
Dim dtStart As Date
Dim dtTemp As Date

dtStart = "04/28/2009"
dtTemp = dtStart
lngRow = 1
Range("A" & lngRow) = dtTemp
Do
lngRow = lngRow + 1
dtTemp = DateAdd("m", 1, dtTemp)
Range("A" & lngRow) = dtTemp
Loop Until lngRow = 100

End Sub


yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
--
If this post helps click Yes
---------------
Jacob Skaria


"sgl" wrote:

I have the following

1 - A Start Date
2 - This Date must be incremented by a certain period (months, quarters,
semi-annualy etc) each time the Loop passes
3 - Need to write the result into a range
4 - "Max range" to write this in is 100 rows (calculated bewteen two ranges
- say A1:A100). loop must stop at 100.

Can someone help write this simple code for me
thanks/sgl

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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 10:38 AM.

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

About Us

"It's about Microsoft Excel"