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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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!
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,666
Members
449,091
Latest member
peppernaut

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