Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Stop a loop when certain data is found

I have inherited this code from someone else. I want the loop to stop when it
comes to something other than "PO De-Expedite". I have tried several
different things w/o success. The code has to churn through a couple of
thousand rows of data and it is extremely slow so I inserted a sort which
puts all potentially deletable (is that a word?) rows at top.



Dim LastCell
Dim C_LastCell
Dim NumberVal As Long
Dim temp
Dim x As Long
Dim Delete_Flag As Boolean
Dim RightNow As Date

x = 2
RightNow = Date

' Find the last populated cell in the 'A' column and setup for all other
columns

Range("A1").Select
LastCell =
ActiveCell.SpecialCells(xlLastCell).Address(RowAbs olute:=False, _

ColumnAbsolute:=False)
NumberVal = Right(LastCell, (Len(LastCell) - 1))
C_LastCell = "C" & NumberVal

' Delete all PO De-Expedite rows where the Dock Date is more than 56 days
out.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select

If Left(ActiveCell.Value, 14) = "PO De-Expedite" Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
End If
End If
Next x
--
Help greatly appreciated - Jeannell
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,311
Default Stop a loop when certain data is found

Change your If statement.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select
If Left(ActiveCell.Value, 14) = "PO De-Expedite" _
Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 _
Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
Else
End If
Else
Exit For
End If
Next x


HTH,
Paul


--

"jsmith" wrote in message
...
I have inherited this code from someone else. I want the loop to stop when
it
comes to something other than "PO De-Expedite". I have tried several
different things w/o success. The code has to churn through a couple of
thousand rows of data and it is extremely slow so I inserted a sort which
puts all potentially deletable (is that a word?) rows at top.



Dim LastCell
Dim C_LastCell
Dim NumberVal As Long
Dim temp
Dim x As Long
Dim Delete_Flag As Boolean
Dim RightNow As Date

x = 2
RightNow = Date

' Find the last populated cell in the 'A' column and setup for all other
columns

Range("A1").Select
LastCell =
ActiveCell.SpecialCells(xlLastCell).Address(RowAbs olute:=False, _

ColumnAbsolute:=False)
NumberVal = Right(LastCell, (Len(LastCell) - 1))
C_LastCell = "C" & NumberVal

' Delete all PO De-Expedite rows where the Dock Date is more than 56
days
out.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select

If Left(ActiveCell.Value, 14) = "PO De-Expedite" Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
End If
End If
Next x
--
Help greatly appreciated - Jeannell



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Stop a loop when certain data is found

Many thanks Paul - That worked perfectly!
--
Jeannell


"PCLIVE" wrote:

Change your If statement.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select
If Left(ActiveCell.Value, 14) = "PO De-Expedite" _
Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 _
Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
Else
End If
Else
Exit For
End If
Next x


HTH,
Paul


--

"jsmith" wrote in message
...
I have inherited this code from someone else. I want the loop to stop when
it
comes to something other than "PO De-Expedite". I have tried several
different things w/o success. The code has to churn through a couple of
thousand rows of data and it is extremely slow so I inserted a sort which
puts all potentially deletable (is that a word?) rows at top.



Dim LastCell
Dim C_LastCell
Dim NumberVal As Long
Dim temp
Dim x As Long
Dim Delete_Flag As Boolean
Dim RightNow As Date

x = 2
RightNow = Date

' Find the last populated cell in the 'A' column and setup for all other
columns

Range("A1").Select
LastCell =
ActiveCell.SpecialCells(xlLastCell).Address(RowAbs olute:=False, _

ColumnAbsolute:=False)
NumberVal = Right(LastCell, (Len(LastCell) - 1))
C_LastCell = "C" & NumberVal

' Delete all PO De-Expedite rows where the Dock Date is more than 56
days
out.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select

If Left(ActiveCell.Value, 14) = "PO De-Expedite" Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
End If
End If
Next x
--
Help greatly appreciated - Jeannell




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,311
Default Stop a loop when certain data is found

You're welcome.

--

"jsmith" wrote in message
...
Many thanks Paul - That worked perfectly!
--
Jeannell


"PCLIVE" wrote:

Change your If statement.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select
If Left(ActiveCell.Value, 14) = "PO De-Expedite" _
Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 _
Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
Else
End If
Else
Exit For
End If
Next x


HTH,
Paul


--

"jsmith" wrote in message
...
I have inherited this code from someone else. I want the loop to stop
when
it
comes to something other than "PO De-Expedite". I have tried several
different things w/o success. The code has to churn through a couple of
thousand rows of data and it is extremely slow so I inserted a sort
which
puts all potentially deletable (is that a word?) rows at top.



Dim LastCell
Dim C_LastCell
Dim NumberVal As Long
Dim temp
Dim x As Long
Dim Delete_Flag As Boolean
Dim RightNow As Date

x = 2
RightNow = Date

' Find the last populated cell in the 'A' column and setup for all
other
columns

Range("A1").Select
LastCell =
ActiveCell.SpecialCells(xlLastCell).Address(RowAbs olute:=False, _

ColumnAbsolute:=False)
NumberVal = Right(LastCell, (Len(LastCell) - 1))
C_LastCell = "C" & NumberVal

' Delete all PO De-Expedite rows where the Dock Date is more than 56
days
out.

For x = 2 To NumberVal
Delete_Flag = False
Range("M" & x).Select

If Left(ActiveCell.Value, 14) = "PO De-Expedite" Then
Range("L" & x).Select
If ActiveCell.Value RightNow + 56 Then
Rows(x & ":" & x).Select
Selection.Delete Shift:=xlUp
x = x - 1
End If
End If
Next x
--
Help greatly appreciated - Jeannell






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
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 2 December 4th 06 09:25 PM
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 2 December 4th 06 05:19 PM
Loop QUESTION to end of data range... mniccole Excel Worksheet Functions 0 December 4th 06 03:59 PM
Vlookup data wrong if the small value found are same Fanny Excel Discussion (Misc queries) 4 January 11th 06 03:05 AM
Data Source Name Not Found Justin Tyme Excel Worksheet Functions 0 June 16th 05 11:45 PM


All times are GMT +1. The time now is 05:30 PM.

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"