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

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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.
 
Upvote 0
It should be
VBA Code:
If searchValue Is Nothing Then
 
Upvote 0
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
 
Upvote 0
@vbaNumpty
In future please do not edit your posts after other members have posted. It just cause confusion, so I have changed it back.
 
Upvote 0
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. :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top