vba - .find error object not set

georgep93

New Member
Joined
Feb 15, 2017
Messages
24
Code:
                                Set check = dataws.Range("A:A").Find(What:=.Cells(i, 2).Value, LookAt:=xlPart).Offset(0, 1)
                                
                                If Not check Is Nothing Then
                                   .Cells(i, 13) = check.Value
                                Else
                                    .Cells(i, 13) = "N/A"
                                End If

I thought the above would handle an error if nothing was found, the code errors on the first line saying it's not set. I know that it won't set but i want it to write N/A if it doesn't find anything. Anyone have a better way of doing it?

Thanks.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
georgep93,

In order to assist you it would help us if you posted all of your macro code using code tags.

When posting VBA code, please use Code Tags - like this:

[code=rich]

'Paste your code here.

[/code]
 
Upvote 0
Try

Code:
Set check = dataws.Range("A:A").Find(What:=.Cells(i, 2).Value, LookAt:=xlPart)
                                
If Not check Is Nothing Then
   .Cells(i, 13) = check.Offset(0, 1).Value
Else
    .Cells(i, 13) = "N/A"
End If

M.
 
Upvote 0
hi sorry think i've wasted your time here i found it straight after posting.. typical:

Code:
                                Set check = dataws.Range("A:A").Find(What:=.Cells(i, 2).Value, LookAt:=xlPart)
                                If Not check Is Nothing Then
                                   .Cells(i, 13) = check.Offset(0, 1).Value
                                Else
                                    .Cells(i, 13) = "N/A"
                                End If
just needed to move the offset
 
Upvote 0

Forum statistics

Threads
1,216,104
Messages
6,128,856
Members
449,472
Latest member
ebc9

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