Multiple Column Data Validation

BuzzG

Board Regular
Joined
Sep 8, 2002
Messages
67
Is there a way to use data validation on a cell that refers to a list but the combo box shows a multi column range. Example: Cell value needs to be a valid projectID (A65110, ...). When the drop down box is viewed the user sees a list of projectID's and projectNames (A65110 Jones Project, ...). When the user selects from the list, the cell is populated with just the projectID. Access has a feature linking a field (cell) to other fields to assist data input. Does Excel have a similar feature with data validation?
BuzzG
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

This could be better achieved wit VBA/Combobox Not Data Validation.
However,with a bit of trickery,I managed a workaround.

Proceed as Follows:

Let's suppose that the Ranges with ProjectID and ProjectNamesare respectively A1:A20 And B1:B20 .

In a new Column, let's say Column C , Select the Range C1:C20 AND Array Enter the following Formula: {=A1:A20} Press Ctrl+Shift+Enter.

Now,each cell in this new Column(C) will be given a custom Format.
So, Cell C1 for example will be Formatted as follows:

Click Format>Cell>Number Tab>Custom and Type @ "JonesProject" in the Type Area.

After formatting Cell C1, it will display A65110 JonesProject But the Actual underlying value is in fact A65110.
Carry on formatting the rest of the Cells in Column C in the same way with their respective cells in Columns A and B .

Select the Cell with the Data Validation and assign to it the List refering to the range C1:C20.

Column C can now be safely Hidden.

After performing the steps above,you will find that on clicking the Data Validation Arrow,the Combobox shows the ProjectID AND ProjectNames But the Cell is Populated with just the ProjectID


Obviously,if the List of Projects is very long,Custom-formatting each and every cell can be very tedious but I couldn't think of a better solution.

Let me know if any Probs.
 
Upvote 0
Clever work-around but I don't think it will work in my situation as my list is long and changes frequently. Thanks anyway.
BuzzG
 
Upvote 0
Hi,

If the list is long and changes all the time then you can use VBA to carry out all the steps for you.

:warning: If you want to experiment with this technic ,please back up your data before :warning:

In the code below,I assume that ProjectIDs and ProjectNames are respectively in Columns A and B Starting at Row 2. Row 1 is assumed to be housing the Column Headings.

I also assume that the Cell with the Data Validation is Cell G2

The Code also assumes that the Extra Column which eventually will be Hidden is ColumnC.

Adapt all the above to suit your data arrangement.

Note that the code will execute everytime you add a new ProjectId/ProjectName Or Edit an existing one !

Therefore,you can just add a mock ProjectId at the bottom of your list for the Code to fire and then remove it.

RightClick the Worksheet Tab, Choose View Code and Paste the code below:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
        If Target.Column = 1 Or Target.Column = 2 Then
            UpdateValidationCell
            Target.Select
        End If
End Sub

Sub UpdateValidationCell()
    Set ProjectIdRange = Range(Range("A2"), Range("A2").End(xlDown))
    Set ValidtListRange = Range(Range("C2"), Range("C2").End(xlDown))
    For Each CL In ProjectIdRange.Cells
        CL.Offset(0, 2).NumberFormat = "General"
        CL.Offset(0, 2).Formula = "=" & (CL.Address)
        CL.Offset(0, 2).NumberFormat = "@    " & """" & CL.Offset(0, 1).Value & """"
    Next
    Set ValidtListRange = Range(Range("C2"), Range("C2").End(xlDown))
    Range("G2").Select
    Selection.Validation.Delete
    Selection.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=" & ValidtListRange.Address
    Columns("C").Hidden = True
End Sub

As I mentioned in my previous post, Using a ComboBox would have been much easier to program :huh: .Having said that,Getting similar results using Data Validation is much more challenging. :wink:

Good Luck.
 
Upvote 0
The drawback to that approach is an ever growing list of custom formats. Is there a limit to the number of custom formats per workbook? I'm interested in a more direct solution. Your thoughts on setting up a combo box?
Thanks for taking the time to help.
BuzzG.
 
Upvote 0
You can ignore some of your coding, thus it will be better....

Private Sub Worksheet_Change(ByVal Target As Range)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
If Target.Column = 1 Or Target.Column = 2 Then<o:p></o:p>
UpdateValidationCell<o:p></o:p>
Target.Select<o:p></o:p>
End If<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
Sub UpdateValidationCell()<o:p></o:p>
Set ProjectIdRange = Range(Range("A2"), Range("A2").End(xlDown))<o:p></o:p>
Set ValidtListRange = Range(Range("C2"), Range("C2").End(xlDown))<o:p></o:p>
For Each CL In ProjectIdRange.Cells<o:p></o:p>
CL.Offset(0, 2).NumberFormat = "General"<o:p></o:p>
CL.Offset(0, 2).Formula = "=" & (CL.Address)<o:p></o:p>
CL.Offset(0, 2).NumberFormat = "@ " & """" & CL.Offset(0, 1).Value & """"<o:p></o:p>
Next<o:p></o:p>
Set ValidtListRange = Range(Range("C2"), Range("C2").End(xlDown))<o:p></o:p>
Columns("C").Hidden = True<o:p></o:p>
End Sub
 
Upvote 0
See if my suggestion in this thread is any use. Note that you would need to remove all the **** from the code. (The **** were introduced when the board software was changed some time ago.)
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,208
Members
453,151
Latest member
Lizamaison

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