Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Delete Loop Error

Hi,

I was given this code on the forum, (cant find my old post), which works
fine, deleting the grey coloured cells, however once it has deleted the lines
I need it errors on this line

Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete

with Run time error 91, object variable or with block variable not set.

The same error appears if there are no grey cells to delete. Am I missing
something from this code?

Thanks
LiAD

Application.FindFormat.Interior.ColorIndex = 15
On Error GoTo Done
Do
Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete
xlShiftUp
Loop
Done:
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Delete Loop Error

to be expected. The line inherently does two things , it sets the range and
then deletes the row. If there's no cells detected, then trying to delete
from a null raises an error

in the following code sample, I've split the line into the two parts so that
if you step (F8) through it, you'll see what happens.
Try it on a blank column, a column with contiguous data and a column with a
break in the data..there's no error, simply that the range isn't set so
remains null and the IF takes care of it.

Sub rubout()
Dim target As Range
Set target = Range("L3:L" & Rows.Count).Find("", SearchFormat:=True)
If Not target Is Nothing Then
target.EntireRow.Delete
End If
End Sub

"LiAD" wrote:

Hi,

I was given this code on the forum, (cant find my old post), which works
fine, deleting the grey coloured cells, however once it has deleted the lines
I need it errors on this line

Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete

with Run time error 91, object variable or with block variable not set.

The same error appears if there are no grey cells to delete. Am I missing
something from this code?

Thanks
LiAD

Application.FindFormat.Interior.ColorIndex = 15
On Error GoTo Done
Do
Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete
xlShiftUp
Loop
Done:

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Delete Loop Error

Try the below which will loop until all rows are found...

Application.FindFormat.Interior.ColorIndex = 15
Do
Set varFound = Range("L3:L" & Rows.Count).Find("", SearchFormat:=True)
If Not varFound Is Nothing Then varFound.EntireRow.Delete xlShiftUp
Loop Until varFound Is Nothing

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Hi,

I was given this code on the forum, (cant find my old post), which works
fine, deleting the grey coloured cells, however once it has deleted the lines
I need it errors on this line

Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete

with Run time error 91, object variable or with block variable not set.

The same error appears if there are no grey cells to delete. Am I missing
something from this code?

Thanks
LiAD

Application.FindFormat.Interior.ColorIndex = 15
On Error GoTo Done
Do
Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete
xlShiftUp
Loop
Done:

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 386
Default Delete Loop Error

Spot on once again

Thanks!

"Jacob Skaria" wrote:

Try the below which will loop until all rows are found...

Application.FindFormat.Interior.ColorIndex = 15
Do
Set varFound = Range("L3:L" & Rows.Count).Find("", SearchFormat:=True)
If Not varFound Is Nothing Then varFound.EntireRow.Delete xlShiftUp
Loop Until varFound Is Nothing

If this post helps click Yes
---------------
Jacob Skaria


"LiAD" wrote:

Hi,

I was given this code on the forum, (cant find my old post), which works
fine, deleting the grey coloured cells, however once it has deleted the lines
I need it errors on this line

Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete

with Run time error 91, object variable or with block variable not set.

The same error appears if there are no grey cells to delete. Am I missing
something from this code?

Thanks
LiAD

Application.FindFormat.Interior.ColorIndex = 15
On Error GoTo Done
Do
Range("L3:L" & Rows.Count).Find("", SearchFormat:=True).EntireRow.delete
xlShiftUp
Loop
Done:

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 & Delete Jenna Excel Discussion (Misc queries) 3 January 24th 07 06:34 PM
Loop and delete [email protected] Excel Programming 4 October 12th 06 02:52 PM
A loop to delete Nikki Excel Programming 1 December 3rd 04 07:59 PM
Simple For-Loop gives 1004 error using variable to EntireRow.Delete EdMX Excel Programming 3 December 2nd 04 02:43 AM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 01:25 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"