Compare the value of an inputbox against data in 1 column

Grod

New Member
Joined
Nov 18, 2003
Messages
7
How would one go about validating user input against data in one 1 column?

I have gathered the input and stored it to a defined string variable which is used as criteria for an autofilter. As the autofilter triggers another process I would like to qualify the users input before running the autofilter. My intent is to complete this section of code with an If statement to advise the user if the input is incorrect and direct them to retry their input.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

sbendbuckeye

Active Member
Joined
Nov 26, 2003
Messages
440
Can you post some sample data to show what you are trying to do (eg what is the input box returning and what does the data in your comparison column look like). Good Luck!
 

Grod

New Member
Joined
Nov 18, 2003
Messages
7
Re: Compare the value of an inputbox against data in 1 colum

The inputbox assigns a value to a variable.

dim FCT as String
FCT = InputBox("Whats the value")
Selection.AutoFilter Field:=3, Criteria1:=FCT, Operator:=xlAnd

At this stage I had the idea that if the value entered is not in the table, the autofilter will not return any value and I can use this fact to check against a blank range. If the range is blank then an if statement will direct my code to one outcome advising the user to try again.
If the range contains the data then the code will continue to complete the activity.

Here is what I tried and it seems to work.

Retry:
dim FCT as String
ThisWorkbook.Sheets("Report").Cells(2, 1).Value = ""

FCT = InputBox("Whats the value")
Selection.AutoFilter Field:=3, Criteria1:=FCT, Operator:=xlAnd

If Len(ThisWorkbook.Sheets("Sheet1").Cells(5, 1).Value) = 0 Then
MsgBox "Value Not Found in your Data! Try again or cancel."
GoTo Retry
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,130,048
Messages
5,639,769
Members
417,111
Latest member
buyukbang

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
Top