Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
for..next statement problem
Just one button
Private Sub CommandButton1_Click() Dim date1 As Date Dim date2 As Date Dim rng As Range date1 = TextBox1.Text date2 = TextBox2.Text For Each cell In Range("F9").CurrentRegion.Cells If cell < date1 Or cell date2 Then If rng Is Nothing Then Set rng = cell Else Set rng = Union(rng, cell) End If End If Next cell If Not rng Is Nothing Then rng.EntireRow.Delete End Sub -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "s_ali_hassan" wrote in message news:s_ali_hassan.29ebzz_1150295403.5044@excelforu m-nospam.com... 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 enter from which dates they would like the info to and from, then the other dates that are not in the range will all be deleted (the whole rows 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 ive tried loads of things, but still unable to make the loop somehow stop. pls anyone help me on this! any help appreciated. thanks -- s_ali_hassan ------------------------------------------------------------------------ s_ali_hassan's Profile: http://www.excelforum.com/member.php...o&userid=35325 View this thread: http://www.excelforum.com/showthread...hreadid=551870 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF STATEMENT PROBLEM | Excel Worksheet Functions | |||
IF Statement problem | New Users to Excel | |||
IF Statement Problem | Excel Worksheet Functions | |||
If Statement Problem | Excel Programming | |||
Re - If Statement Problem | Excel Programming |