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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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