Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
I am trying to validate user input against data that is in the fourth column
of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
My first suggestion when input must come from a fixed list would be to use a
listbox or combobox for the user to select, rather than type, the values - it eliminates the chance of mismatches based on typos, etc and is much easier and less frustrating for the user, plus you would not need to worry about validation since you know the answer must be in the list. Having said that, if you still want to use typed input and validate it, you can use the Find method to see if the input value is in the column: Dim Found as Boolean, Cancelled as Boolean Found = False Cancelled = False While (Not Found) And (Not Cancelled) Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") Cancelled = (Cliname = False) Found = Not(Sheets("data").Range("D:D").Find(Cliname) Is Nothing) If (Not Found) And (Not Cancelled) Then MsgBox "Invalid Client Name; retry" WEnd HTH "lewscannon" wrote: I am trying to validate user input against data that is in the fourth column of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
The easiest way is to use DataValidation in the cell.
otherwise you could do something like this: Dim y As Integer On Error Resume Next y = WorksheetFunction.Match(Cliname, Sheets("data").Range("D:D"), 0) On Error GoTo 0 If y 0 Then MsgBox " match" Else: MsgBox "no match" End If -- steveB Remove "AYN" from email to respond "lewscannon" wrote in message ... I am trying to validate user input against data that is in the fourth column of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
A simple match can do this:
If WorksheetFunction.Match(Cliname,Sheets("Data").Ran ge("D:D"),0) = "#N/A" -- steveB Remove "AYN" from email to respond "lewscannon" wrote in message ... I am trying to validate user input against data that is in the fourth column of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
How would I be able to create a listbox based upon the contents of that
column? The worksheet could contain as many as 30,000 rows, though there would probably not be more than 5 different selections. Also, the data for the entire sheet will change periodically, depending on what is copied and pasted into it (though the column containing the listbox items would remain in the same place (Column D). Thanks. "K Dales" wrote: My first suggestion when input must come from a fixed list would be to use a listbox or combobox for the user to select, rather than type, the values - it eliminates the chance of mismatches based on typos, etc and is much easier and less frustrating for the user, plus you would not need to worry about validation since you know the answer must be in the list. Having said that, if you still want to use typed input and validate it, you can use the Find method to see if the input value is in the column: Dim Found as Boolean, Cancelled as Boolean Found = False Cancelled = False While (Not Found) And (Not Cancelled) Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") Cancelled = (Cliname = False) Found = Not(Sheets("data").Range("D:D").Find(Cliname) Is Nothing) If (Not Found) And (Not Cancelled) Then MsgBox "Invalid Client Name; retry" WEnd HTH "lewscannon" wrote: I am trying to validate user input against data that is in the fourth column of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation
Whether you use a listbox, or combobox
Set ListFillRange $A:$A You can set the properties to only accept a match and the list will scroll to the closest match Used DataValidation Set to List Source =$A:$A You can set this to not accept an entry unless it is in the list. You can do all of these with or without code. -- steveB Remove "AYN" from email to respond "lewscannon" wrote in message ... How would I be able to create a listbox based upon the contents of that column? The worksheet could contain as many as 30,000 rows, though there would probably not be more than 5 different selections. Also, the data for the entire sheet will change periodically, depending on what is copied and pasted into it (though the column containing the listbox items would remain in the same place (Column D). Thanks. "K Dales" wrote: My first suggestion when input must come from a fixed list would be to use a listbox or combobox for the user to select, rather than type, the values - it eliminates the chance of mismatches based on typos, etc and is much easier and less frustrating for the user, plus you would not need to worry about validation since you know the answer must be in the list. Having said that, if you still want to use typed input and validate it, you can use the Find method to see if the input value is in the column: Dim Found as Boolean, Cancelled as Boolean Found = False Cancelled = False While (Not Found) And (Not Cancelled) Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") Cancelled = (Cliname = False) Found = Not(Sheets("data").Range("D:D").Find(Cliname) Is Nothing) If (Not Found) And (Not Cancelled) Then MsgBox "Invalid Client Name; retry" WEnd HTH "lewscannon" wrote: I am trying to validate user input against data that is in the fourth column of a worksheet named "data". The amount of rows in this sheet will vary This is how I receive the input from the user: Cliname = InputBox(Prompt:="Enter Client Name", Title:="Client Name") How do I do this? Thanks in advance. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Validation Data using Validation Table cell range..... | Excel Discussion (Misc queries) | |||
Data validation with validation lists and combo boxs | Excel Discussion (Misc queries) | |||
Validation (Drop down list vs simple text length validation) | Excel Programming | |||
Validation (Drop down list vs simple text length validation) | Excel Programming | |||
Validation (Drop down list vs simple text length validation) | Excel Programming |