Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
returning back to loop check condition without completing the loop | Excel Programming | |||
Loop to Filter, Name Sheets. If Blank, Exit Loop | Excel Programming | |||
(Complex) Loop within loop to create worksheets | Excel Programming | |||
Advancing outer Loop Based on criteria of inner loop | Excel Programming | |||
Problem adding charts using Do-Loop Until loop | Excel Programming |