Do while - I think it is going into Endless Loop: Been a while didnt use this loop

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
<TABLE style="WIDTH: 52pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=69><COLGROUP><COL style="WIDTH: 52pt; mso-width-source: userset; mso-width-alt: 2523" width=69><TBODY><TR style="HEIGHT: 13.5pt" height=18><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 52pt; HEIGHT: 13.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=18 width=69 align=right>A1 value = 1/1/2012 </TD></TR><TR style="HEIGHT: 13.5pt" height=18><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 13.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=18 align=right>A2 value = 1/1/2011</TD></TR></TBODY></TABLE>​


I want to loop and give me all the dates in col a from Jan1 11 to Jan 1 12.

Thanks for helping!:)
My Current Code:
Code:
[/FONT]
[FONT=Courier New]Sub try()
Dim rw As Long
rw = 3
Do While Cells(rw, 1).Value > Range("A1").Value
 Cells(rw, 1).Value = Cells(rw, 1).Offset(-1, 0).Value + 1
 rw = rw + 1
Loop
End Sub
 

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.
Should it be less than instead of greater than?
 
Upvote 0
I think it should be less then. It should cont. adding up dates Jan 1 /11 is in A3, a4 should be jan 2/2011 ......till jan 1/2012.
Basically trying to generate date.

Thanks again.

I also tried this but wont work both ways...it keeps going till i end it by pressing esp.
Code:
[FONT=Courier New]Sub try()[/FONT]
[FONT=Courier New]Dim rw As Long[/FONT]
[FONT=Courier New]Dim x[/FONT]
[FONT=Courier New]x = ActiveSheet.Range("A1").Value[/FONT]
[FONT=Courier New]rw = 3[/FONT]
[FONT=Courier New]While Cells(rw, 1).Value < x[/FONT]
[FONT=Courier New]Cells(rw, 1).Value = Cells(rw, 1).Offset(-1, 0).Value + 1[/FONT]
[FONT=Courier New]rw = rw + 1[/FONT]
[FONT=Courier New]Wend[/FONT]
[FONT=Courier New]end sub[/FONT]
 
Upvote 0
pedie,


I want to loop and give me all the dates in col a from Jan1 11 to Jan 1 12.



Sample data before the macro:


Excel Workbook
A
11/1/2012
21/1/2011
3
4
5
6
7
8
9
10
Sheet1





After the macro with most of the rows hidden for brevity:


Excel Workbook
A
11/1/2012
21/1/2011
31/2/2011
41/3/2011
51/4/2011
36212/27/2011
36312/28/2011
36412/29/2011
36512/30/2011
36612/31/2011
3671/1/2012
368
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub try()
Dim rw As Long
rw = 3
Do Until Cells(rw - 1, 1).Value = Range("A1").Value
 Cells(rw, 1).Value = Cells(rw, 1).Offset(-1, 0).Value + 1
 rw = rw + 1
Loop
End Sub


Then run the try macro.
 
Upvote 0
Hiker, thanks for walking me through this...

Seeing yours tried this and works perfect! Your works perfect!:)

Thanks again
Code:
[/FONT]
[FONT=Courier New]Sub TRY3()
Dim rw
rw = 3[/FONT]
[FONT=Courier New]Do While Cells(rw - 1, 1).Value <> Range("A1").Value
Cells(rw, 1).Value = Cells(rw, 1).Offset(-1, 0).Value + 1
rw = rw + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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
Back
Top