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
 

V_Malkoti

Well-known Member
Joined
Jun 10, 2015
Messages
898
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:

Forum statistics

Threads
1,082,587
Messages
5,366,481
Members
400,893
Latest member
aoreilly2

Some videos you may like

This Week's Hot Topics

Top