View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
s_ali_hassan[_3_] s_ali_hassan[_3_] is offline
external usenet poster
 
Posts: 1
Default for..next statement problem


I`m having a bit of a problem with a for...next loop.
In the worksheet ive got a column which has a list of dates in.
What i need to do is for a form to pop-up and ask the user to ente
from which dates they would like the info to and from, then the othe
dates that are not in the range will all be deleted (the whole row
wiill be deleted) will all be deleted.

my code is as follows:
Private Sub CommandButton1_Click()

Dim date1 As Date

date1 = TextBox1.Text

Range("F9").Select 'select the first cell with the date in

For Each cell In ActiveCell.CurrentRegion.Cells

If ActiveCell = "" Then CommandButton2_Click
If ActiveCell < date1 Then ActiveCell.EntireRow.Delete
If ActiveCell date1 Then ActiveCell.Offset(1, 0).Activate

Next

End Sub

Private Sub CommandButton2_Click()

Dim date2 As Date

date2 = TextBox2.Text

Range("F9").Select

For Each cell In ActiveCell.CurrentRegion.Cells

If ActiveCell date2 Then ActiveCell.EntireRow.Delete
If ActiveCell < date2 Then ActiveCell.Offset(1, 0).Activate

Next

End Sub

What happens is, it just gets stuck into a continuous loop, and iv
tried loads of things, but still unable to make the loop somehow stop.

pls anyone help me on this! any help appreciated.

thank

--
s_ali_hassa
-----------------------------------------------------------------------
s_ali_hassan's Profile: http://www.excelforum.com/member.php...fo&userid=3532
View this thread: http://www.excelforum.com/showthread.php?threadid=55187