Why do I get an object error 91 on this usage of code?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
160
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
 Set findValue = imageB.Range("X:X").Find(what:=myarray(j, 1), _
            LookIn:=xlValues, lookat:=xlWhole)
        'Using to match values to original launched data
        Set searchValue = dashB.Range("X:X").Find(what:=myarray(j, 1), _
            LookIn:=xlValues, lookat:=xlWhole)
            
            'if the order is new addition
            If searchValue = "" Then

the line:

If searchValue = "" Then

returns the 91 error.

How can I make it so that my If portion does its thing if the searchValue variable returns nothing (i.e doesn't exist in the search range of the find function)?

I have tried making the if searchvalue = Nothing then, but it didn't like that either.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
13,530
Office Version
  1. 365
Platform
  1. Windows
You need to use Is instead of =
VBA Code:
If searchvalue Is Nothing Then
Although it is more common to use
VBA Code:
If Not searchvalue Is Nothing Then
In order to test if something was found rather than testing to see if it wasn't found.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,252
Office Version
  1. 365
Platform
  1. Windows
It should be
VBA Code:
If searchValue Is Nothing Then
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
13,530
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Thanks Jason!
This thread is going to confuse anyone who didn't see your post before you edited it 🤯
 

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
160
Office Version
  1. 365
Platform
  1. Windows
This thread is going to confuse anyone who didn't see your post before you edited it 🤯
I found the answer through trial and error and posted it what appears to be a split second before you and fluff. I edited my response cause it was weird to answer my own question and use the solution on my post rather than yours. But yes it may confuse some lol
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,252
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

@vbaNumpty
In future please do not edit your posts after other members have posted. It just cause confusion, so I have changed it back.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,252
Office Version
  1. 365
Platform
  1. Windows
I edited my response cause it was weird to answer my own question and use the solution on my post
There is nothing wrong with that, in fact it's better to leave it that way, as it shows your are trying to sort things out yourself. :)
 

Forum statistics

Threads
1,141,070
Messages
5,704,112
Members
421,327
Latest member
Msh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top