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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,213,492
Messages
6,113,967
Members
448,537
Latest member
Et_Cetera

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