• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 118
  • Last Modified:

Object Required error

I have the below code that is falling over with Object Required

It deletes all the items it is looking for and if there is other data in the cell it continues through to the next piece of code but if all the cells are blank it fall over.

Can an expert help please


Set SrchRng = ActiveSheet.Range("A2", ActiveSheet.Range("A65536").End(xlUp))
    Do
        Set c = SrchRng.Find("GD Market*", LookIn:=xlValues)
        If Not c Is Nothing Then c.EntireRow.Delete
    Loop While Not c Is Nothing
   
    Range("A2").Select
         If ActiveCell = "" Then Exit Sub
0
Jagwarman
Asked:
Jagwarman
  • 3
  • 3
1 Solution
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
I don't get that error. Can you please publish your workbook.
0
 
JagwarmanAuthor Commented:
Sheet 2 works fine Sheet 1 gets the error
Object-Error.xlsm
0
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
This works:
 
Sub RemoveSome()
 
Set srchrng = ActiveSheet.Range("A2", ActiveSheet.Range("A65536").End(xlUp))
    Do
        Set c = srchrng.Find("GD Market*", LookIn:=xlValues)
        If Not c Is Nothing Then
            If srchrng.Rows().Count = 1 Then
                c.EntireRow.Delete
                Exit Do
            Else
                c.EntireRow.Delete
            End If
        End If
    Loop While Not c Is Nothing
   
    Range("A2").Select
         If ActiveCell = "" Then Exit Sub
        
      Sheets("Sheet2").Select
        
End Sub

Open in new window

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
JagwarmanAuthor Commented:
Yes it does, many thanks
0
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
It's because your search range went down to zero rows, which makes it not a valid range.
0
 
JagwarmanAuthor Commented:
Ah right thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now