Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
On Error Resume Next (when next statement is Do Loop ...) | Excel Discussion (Misc queries) | |||
how to put a loop in a macro? | New Users to Excel | |||
Loop time seems dependent on unrelated workbook - Why? | Excel Worksheet Functions | |||
Loop gone crazy | Excel Discussion (Misc queries) | |||
Do Loop | Excel Discussion (Misc queries) |