Seeing if a value is on another Sheet function

dpiano1984

New Member
Joined
Feb 8, 2013
Messages
14
Hello all,

I'm trying to write a function for one of my reports that would perform a boolean function to see whether or not a cell's value is on another sheet in the workbook. Pretty much (If it's on that sheet, Yes, if not, see if it's on this sheet). Here's what I have so far

Code:
Public Function ISTHERE(CUSIP As String) As Boolean


If Sheet4.Columns("B").Find(CUSIP, LookIn:=xlFormulas, Lookat:=xlWhole) Is Nothing Then
    If Sheet5.Columns("B").Find(CUSIP, LookIn:=xlFormulas, Lookat:=xlWhole) Is Nothing Then
        ISTHERE = False
    Else
        ISTHERE = True
    End If
Else
    ISTHERE = True
End If




End Function

I would use the function like this in the spreadsheet:

=if(ISTHERE(A2)=TRUE,"Yes","No")

I get yes everytime. What am I doing wrong? Or am I even visualizing the answer correctly?

Thanks a bunch!
Dave
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Why can't you use the Function in the sheet to return "Yes" or "No" as below:-
Code:
Public Function ISTHERE(CUSIP As String) As String 'Boolean
Dim rng As Range
Application.Volatile
Set rng = Sheets("Sheet27").Columns("B:B").Find(CUSIP, LookIn:=xlFormulas, Lookat:=xlWhole)
If rng Is Nothing Then
    Set rng = Sheets("Sheet26").Columns("B:B").Find(CUSIP, LookIn:=xlFormulas, Lookat:=xlWhole)
    If rng Is Nothing Then
        ISTHERE = "No" 'False
    Else
        ISTHERE = "Yes" 'True
    End If
Else
    ISTHERE = "Yes" 'True
End If
End Function
 
Upvote 0

Forum statistics

Threads
1,216,088
Messages
6,128,744
Members
449,466
Latest member
Peter Juhnke

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