Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Cleaner Error trap in Loop.

In the following code, Im tying to go down the Combined worksheets
columns cells locating the values of the cell in the worksheet VoidReq &
delete that sheets row if found, continuing down the Combined worksheets
columns cell until it runs into empty cell.

The problem is sometimes it will not find the value on the Combined sheet
& I want it to skip over deleting a row & continue on down the column until
it gets to the empty cell at the bottom. I have an error catch Error GoTo
FindAgain but in running the code it seems to only skip over one not found
entry & when it runs into another not found entry it craps out.

I know the code is I have is probably sloppy & I apologize but Im still a
struggling learner

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo FindAgain
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Cleaner Error trap in Loop.

OnError works differently than you would think. You cannot GoTo where you
want code to continue executing directly. You have to GoTo an error handler
which then Resumes where you want the code to continue. Here's the rule:
Every OnError must have a matching Resume. So:

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo NoMatch ''<<CHANGED
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1).Select ''<<Junk deleted
End If
Loop
,,,,,, ''Whatever else you may have
Exit Sub <<ADDED -This goes at the end of the sub
NoMatch: <<ADDED
Resume FindAgain <ADDED
End Sub

PS I didn't check that the rest of your code runs okay,
--
Jim
"plys" wrote in message
...
In the following code, I'm tying to go down the "Combined" worksheet's
column's cells locating the values of the cell in the worksheet "VoidReq"
&
delete that sheets row if found, continuing down the "Combined" worksheet's
column's cell until it runs into empty cell.

The problem is sometimes it will not find the value on the "Combined"
sheet
& I want it to skip over deleting a row & continue on down the column
until
it gets to the empty cell at the bottom. I have an error catch "Error
GoTo
FindAgain" but in running the code it seems to only skip over one not
found
entry & when it runs into another not found entry it craps out.

I know the code is I have is probably sloppy & I apologize but I'm still a
struggling learner.

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo FindAgain
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop





  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Cleaner Error trap in Loop.

SWEET!!!

So much fun! To step thru the code & watch it work!
& Thx 4 taking the time to explain in a lesson style...

I learned today!
Thx Again.

"Jim Rech" wrote:

OnError works differently than you would think. You cannot GoTo where you
want code to continue executing directly. You have to GoTo an error handler
which then Resumes where you want the code to continue. Here's the rule:
Every OnError must have a matching Resume. So:

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo NoMatch ''<<CHANGED
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1).Select ''<<Junk deleted
End If
Loop
,,,,,, ''Whatever else you may have
Exit Sub <<ADDED -This goes at the end of the sub
NoMatch: <<ADDED
Resume FindAgain <ADDED
End Sub

PS I didn't check that the rest of your code runs okay,
--
Jim
"plys" wrote in message
...
In the following code, I'm tying to go down the "Combined" worksheet's
column's cells locating the values of the cell in the worksheet "VoidReq"
&
delete that sheets row if found, continuing down the "Combined" worksheet's
column's cell until it runs into empty cell.

The problem is sometimes it will not find the value on the "Combined"
sheet
& I want it to skip over deleting a row & continue on down the column
until
it gets to the empty cell at the bottom. I have an error catch "Error
GoTo
FindAgain" but in running the code it seems to only skip over one not
found
entry & when it runs into another not found entry it craps out.

I know the code is I have is probably sloppy & I apologize but I'm still a
struggling learner.

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo FindAgain
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop






  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Cleaner Error trap in Loop.

See http://www.cpearson.com/excel/ErrorHandling.htm for a discussion of
error handling in general.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"plys" wrote in message
...
SWEET!!!

So much fun! To step thru the code & watch it work!
& Thx 4 taking the time to explain in a lesson style...

I learned today!
Thx Again.

"Jim Rech" wrote:

OnError works differently than you would think. You cannot GoTo where
you
want code to continue executing directly. You have to GoTo an error
handler
which then Resumes where you want the code to continue. Here's the rule:
Every OnError must have a matching Resume. So:

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo NoMatch ''<<CHANGED
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1).Select ''<<Junk deleted
End If
Loop
,,,,,, ''Whatever else you may have
Exit Sub <<ADDED -This goes at the end of the sub
NoMatch: <<ADDED
Resume FindAgain <ADDED
End Sub

PS I didn't check that the rest of your code runs okay,
--
Jim
"plys" wrote in message
...
In the following code, I'm tying to go down the "Combined" worksheet's
column's cells locating the values of the cell in the worksheet
"VoidReq"
&
delete that sheets row if found, continuing down the "Combined"
worksheet's
column's cell until it runs into empty cell.

The problem is sometimes it will not find the value on the "Combined"
sheet
& I want it to skip over deleting a row & continue on down the column
until
it gets to the empty cell at the bottom. I have an error catch "Error
GoTo
FindAgain" but in running the code it seems to only skip over one not
found
entry & when it runs into another not found entry it craps out.

I know the code is I have is probably sloppy & I apologize but I'm
still a
struggling learner.

Do While Not IsEmpty(ActiveCell)
If IsEmpty(ActiveCell) Then
Exit Do
Else
Vfind = ActiveCell.Value
Sheets("Combined").Select
On Error GoTo FindAgain
Cells.Find(What:=Vfind, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
FindAgain: Sheets("VoidReq").Select
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Loop








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
On Error Resume Next (when next statement is Do Loop ...) EagleOne Excel Discussion (Misc queries) 2 September 26th 06 03:26 PM
how to put a loop in a macro? Khoshravan New Users to Excel 4 May 14th 06 01:22 PM
Loop time seems dependent on unrelated workbook - Why? Richard Excel Worksheet Functions 2 March 30th 06 11:59 PM
Loop gone crazy Dave Peterson Excel Discussion (Misc queries) 4 December 16th 05 03:38 PM
Do Loop Noemi Excel Discussion (Misc queries) 0 December 8th 05 10:43 PM


All times are GMT +1. The time now is 12:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"