Textbox Value Equal to Value in Range on separate sheet

D3allamerican07

Board Regular
Joined
Jul 22, 2015
Messages
101
Hi, I am using a textbox along with a combobox and command button. I need it to check for 4 things,
1. If there is nothing in the Textbox
2. If the Textbox value is in a range on a separate sheet
3. If the Textbox value is not in a range on a separate sheet
4. Or it should pull up the sheet which is the Textbox value

Here is my code so far...

Private Sub SearchFor_Click()

If TextBox.Value = "" Then
MsgBox "Please enter value"

ElseIf TextBox.Value <> Worksheets("Sheet2").Range("A1:A50").Value Then
MsgBox "No it does not exist"

ElseIf TextBox.Value = Worksheets("Sheet2").Range("A1:A50").Value Then
MsgBox "Yes it exists"

Else
Worksheets(ActiveSheet.TextBox.Value).Activate
End If
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:

Code:
Private Sub SearchFor_Click()
    If TextBox.Value = "" Then
        MsgBox "Please enter value"
    Else
        If Worksheets("Sheet2").Range("A1:A50").Find(What:=TextBox.Value, LookIn:=xlValues, LookAt:=xlWhole) is nothing Then
            MsgBox "No it does not exist"
        Else 
            MsgBox "Yes it exists"
        End If
    End If
End Sub

Condition #4 is not included in this code because I didn't quite understand the scenario in which condition#4 should be executed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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