Data Validation "List" quandary

BillSaffian

New Member
Joined
Dec 29, 2010
Messages
25
I have a spreadsheet that tracks time assigned to a myriad of road/bridge construction projects with project numbers varying from 5 to 10 characters in length (no spaces). A project number may be associated with one or more town depending on the scope of the project. I set up a simple data validation list with all the project numbers and it has worked well. One issue is that it is difficult to remember the town(s) where the projects are located so I altered the validation list to show the project number followed by a space followed by the town name(s). Examples: 12210C Hinsdale/Brattleboro; 42440 Boscawen; 40362 Statewide Resurfacing. This has resulted in an unintended consequence. When the list was only the project number, the user could either pick from the list or type in the complete project number and hit enter. With the combined project number/town name list, activating the pull-down list and choosing an entry from it functions the same but attempting to type the entry still requires the entire entry be typed which is now many characters longer. In both cases, if you start typing in the cell, the list does not activate. Two questions: 1. Is there a way for the list to activate if the user begins typing such that the list eliminates entries not matching the characters entered (for example, typing 122 would eliminate all entries but those starting with 122 such as 12210C Hinsdale/Brattleboro and 12210D Hinsdale/Brattleboro)? 2. Is there a way for the list to show the combined project number / town name value but accept just the project number portion as a valid entry for the cell (i.e. a valid entry would be all characters until the space between the project number and town name is encountered such as 12210C or 42440)? Thanks in advance.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
2. Is there a way for the list to show the combined project number / town name value but accept just the project number portion as a valid entry for the cell (i.e. a valid entry would be all characters until the space between the project number and town name is encountered such as 12210C or 42440)?
Do you still need a solution for this?
I might have a solution using VBA. Let me know if you're interested.
 
Upvote 0
Yes, I would be interested. Thanks.
Here's an example of 2 column data-validation:
Data validation (in range A2:A10) shows ID & Name in the list but only insert ID into the cell.
Helper range: $G$2:$G$11
Helper range is the result of concatenation of ID & Name separated by " : ". You can change the separator in this part of the code:
VBA Code:
 Spr = " : " 'concatenation of ID & Name is separated by " : ", change to suit.
Just make sure the separator is not part of data in col ID & Name.
Data validation formula should refer to the helper range: =$G$2:$G$11
In data-validation, on the Error Alert tab, uncheck mark on "Show error alert after invalid data is entered".

In Sheet1 code window, put this code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo skip:

If Target.Cells.CountLarge > 1 Then Exit Sub
    If Len(Target) = 0 Then Exit Sub
    
    If Not Intersect(Target, Range("A2:A10")) Is Nothing Then 'Range("A2:A10") is range with data validation
        Dim tx As String, Spr As String, c As Range, v
            tx = Target.Value
            Spr = " : " 'concatenation of ID & Name is separated by " : ", change to suit
            If Len(tx) > 0 Then
                
                If InStr(tx, Spr) Then
                    v = Split(tx, Spr)(0)
                    Else
                    v = Target.Value
                End If
                Application.EnableEvents = False
                'Range("E2:E11") is col ID
                Set c = Range("E2:E11").Find(What:=v, LookIn:=xlValues, lookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
                    If Not c Is Nothing Then
                        Target = v
                    Else
                        MsgBox "Wrong Entry"
                        Target.ClearContents
                    End If
               Application.EnableEvents = True
               
            End If
 
    End If

Exit Sub
skip:
Application.EnableEvents = True
MsgBox "Error number " & Err.Number & " : " & Err.Description
End Sub

BillSaffian - 2 column data validation.xlsm
ABCDEFG
1IDIDNAMEhelper column
2A001A001ClydeA001 : Clyde
3A006A002EmilianoA002 : Emiliano
4A007A003RexA003 : Rex
5A004ZacharyA004 : Zachary
6A005RolandA005 : Roland
7A006ParkerA006 : Parker
8A007KeenanA007 : Keenan
9A008AxlA008 : Axl
10A009PatrickA009 : Patrick
11A010ClaytonA010 : Clayton
Sheet1
Cell Formulas
RangeFormula
G2:G11G2=E2&" : "& F2
Cells with Data Validation
CellAllowCriteria
A2:A10List=$G$2:$G$11


BillSaffian - 2 column data validation image.jpg

The workbook:
 
Upvote 0
Thank you very much for your effort. I haven't tried your solution yet but wanted to clarify one thing. My validation list (what you call the helper range) is already created except I don't have the " : " separator which I can easily add. Therefore, I don't need the step that combines the ID and Name columns to create the helper range. If I understand what you've created correctly, the result of the choosing from the list (shown in column A) is just the ID portion (i.e. up to the " : "). This is not what I want. I always want the full combined value to be the result of the users choice. But I was hoping that instead of activating the list and scrolling to it, the user could type the ID number, hit enter and be rewarded with the combined value from the list. Currently if I do this, the ID portion is not recognized, and I get the invalid entry message.

More ideal would be to be able to manually start typing in a column A cell and have this action actuate the validation list display and have the list update as typing occurs to eliminate from the display those entries that don't have the characters being typed until there are either just a few options left on the display allowing the user to choose from the shortened list or the user continues to type until there is only one entry displayed and therefore, hitting enter selects that entry. This is what I had hoped for in question 1 of my original post.
 
Upvote 0
1. Sorry, in post #2 I quoted your second question, it meant that my reply was only to address that second question. And my understanding is you want to accept only project number as valid entry in the cell.
(i.e. a valid entry would be all characters until the space between the project number and town name is encountered such as 12210C or 42440)
So, my understanding is incorrect?

2. As for question #1, about autocomplete data validation, please check this discussion:
excel-365-drop-down-search-function-not-available
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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