Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Using While Wend with Cells.Find

I import data into a worksheet in Excel2007. I want to find the statement "Stop by Reason", and delete it and some rows above and below it. It might appear 1 time, or up to 5 or 6 times. The follwing code will find it, but once all occurances been found and deleted, I get this messsage...
Run time error '91':
Object variable or With block variable not set.

This is the code...
Sub DeleteStopReason()
While Cells.Find(What:="Stop by Reason", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(-9, 0).Range("A1:A14").Select
Selection.EntireRow.Delete
ActiveCell.Select
Wend
End Sub
I do not understand what must be done to coreect this sothat all occurcnes will be deleted and the macro not stop.

Thanks,

Billy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Using While Wend with Cells.Find

On Tuesday, August 14, 2012 11:14:35 AM UTC-5, Billy wrote:
I import data into a worksheet in Excel2007. I want to find the statement "Stop by Reason", and delete it and some rows above and below it. It might appear 1 time, or up to 5 or 6 times. The follwing code will find it, but once all occurances been found and deleted, I get this messsage...

Run time error '91':

Object variable or With block variable not set.



This is the code...

Sub DeleteStopReason()

While Cells.Find(What:="Stop by Reason", After:=ActiveCell, LookIn _

:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _

xlNext, MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Offset(-9, 0).Range("A1:A14").Select

Selection.EntireRow.Delete

ActiveCell.Select

Wend

End Sub

I do not understand what must be done to coreect this sothat all occurcnes will be deleted and the macro not stop.



Thanks,



Billy


Look in the vba help index for FINDNEXT. Try that and post again after if you still can't get it.
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
WEND in VBA Dave F Excel Discussion (Misc queries) 9 April 4th 23 10:37 AM
Simple code to find the empty cells in a range and cells with number Subodh Excel Programming 2 April 30th 10 06:05 AM
Need Cells.find to find first number in a row which is 8000 Kasper Excel Discussion (Misc queries) 9 December 15th 08 02:10 PM
While-Wend loop to fill in nulls tbmarlie Excel Programming 4 October 12th 07 03:51 PM
While ... Wend Andrzej Excel Programming 7 June 24th 05 08:03 PM


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

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"