Why does this not work? Search row 1 report colum 2

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
I want to search a colum on another workbook for a variable "VND" and if found return colum b from that locatin, and if nothing is found default to "MTS".

I get errors on set b.

Code:
Workbooks.Open ("\\JAXentitive.xlsm")  'open book name with vendors
      lr = Range("A1").End(xlDown).Row ' Last Row
      With ("A1:A" & lr)
      Set b = .Find(what = vnd, lookat:=xlWhole, LookIn:=xlValues)
      If Not b Is Nothing Then
      sname = Cells(b.Row, "B").Value
      Else
      sname = "Mts"
      End If
      End With
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Your missing the word "Range" from your with statement.
 
Upvote 0
Thank you, that cleard the error. But my code is not returning the correct results. If it finds the match it returns null, if it is missing it errors out. Is there a better way to do this?
 
Upvote 0
What returns Null if a value is found & what errors out is nothing is found?
 
Upvote 0
Hey Fluff,
Thanks for following up on this for me. I kept try into figure this out sand I found a formatting error on the other workbook. Corrected that and now it is working.
Thanks again.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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