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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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