Linked Data Validation Tables

MeaclH

Board Regular
Joined
Apr 2, 2014
Messages
77
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I am wondering if there is a way to have 2 seperate cells with data validation that are linked somehow, so that when a value is selected in the first table, the other table value reflects the value from the table in the adjacent column. I'd like this to be done from either column, so if a user knows the name of a location but not the 3 letter code they can select that, or vice versa, if a user knows the 3 letter code but not the name they can select that, and the 2 data validation cells will always be matched up.
I am guessing it may be some kind of IF/VLOOKUP combo but have no idea.
Any ideas, I'd love to hear them.

cheers,
Hayden

DAO Almanac.xlsx
ABCDEFGHIJKLMNOPQRST
1CODELOCATION NAMELINE(s)Terminating LocationStabling LocationMeal Break LocationDrivers Depot# of Stabling Roads
2Burnley SidingsBLSACFAircraftWerribeeNONO
3ALBAlbionSunburyNONO
4ALMAlameinAlameinYESNONO
5ALPAlphingtonHurstbridgeNONO
6Terminating LocationYESALTAltonaWerribeeNONO
7Stabling LocationYESARMArmadaleFrankstonNONO
8Meal Break LocationYESASHAshburtonAlameinYESNONO
9Drivers DepotNOASPAspendaleFrankstonNONO
10Stabling Roads5ASVAscot ValeCraigieburnNONO
11LinesAlamein, Lilydale, BelgraveASYAnsteyUpfieldNONO
12AUBAuburnAlamein, Lilydale, BelgraveNONO
13BATBatmanUpfieldYESNONO
14BAYBayswaterBelgraveYESYESNO5
15BBHBrighton BeachSandringhamYESYESNO2
16BBNBlackburnLilydale, BelgraveYESNONO
17BCVBalaclavaSandringhamNONO
18BEGBelgraveBelgraveYESYESNOYES3
19BELBellMerndaNONO
20BENBentleighFrankstonNONO
21BEWBerwickEast PakenhamYESNONO
22BFDBeaconsfieldEast PakenhamNONO
Sheet1
Cells with Data Validation
CellAllowCriteria
G2:H4List=$M$2:$M$22
B2:E4List=$N$2:$N$22
 
Here is the adjusted code with columns P & Q added to the message box, and not sure why I put the "Value not found" box where I did.
VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim lookupval As String
Dim result As Range
Application.EnableEvents = False
On Error GoTo ExitNow
If Not Intersect(Target, Range("A2")) Is Nothing Then
    If Len(Target) = 3 Then
        lookupval = Target
        Set result = Range("M2:M22").Find(lookupval)
        If Not result Is Nothing Then
            MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
            "Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
            "Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"
        Else
            MsgBox "Invalid entry. Try again.", vbCritical, Title:="Value Not Found"
        End If
    Else
        lookupval = Target
        Set result = Range("N2:N22").Find(lookupval)
        If Not result Is Nothing Then
            MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
            "Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
            "Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"
        Else
            MsgBox "Invalid entry. Try again.", vbCritical, Title:="Value Not Found"
        End If
    End If
End If
ExitNow:
Application.EnableEvents = True
End Sub

But to add additional lines to the message box, you can replicate the bolded line:

MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
"Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
"Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"

vbCrLf adds the new line, then I added a string to name the information showing, then the column where it's found.

Make sure you edit the message box in both sections.
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Here is the adjusted code with columns P & Q added to the message box, and not sure why I put the "Value not found" box where I did.
VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim lookupval As String
Dim result As Range
Application.EnableEvents = False
On Error GoTo ExitNow
If Not Intersect(Target, Range("A2")) Is Nothing Then
    If Len(Target) = 3 Then
        lookupval = Target
        Set result = Range("M2:M22").Find(lookupval)
        If Not result Is Nothing Then
            MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
            "Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
            "Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"
        Else
            MsgBox "Invalid entry. Try again.", vbCritical, Title:="Value Not Found"
        End If
    Else
        lookupval = Target
        Set result = Range("N2:N22").Find(lookupval)
        If Not result Is Nothing Then
            MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
            "Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
            "Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"
        Else
            MsgBox "Invalid entry. Try again.", vbCritical, Title:="Value Not Found"
        End If
    End If
End If
ExitNow:
Application.EnableEvents = True
End Sub

But to add additional lines to the message box, you can replicate the bolded line:

MsgBox Range("N" & result.Row) & " " & Range("M" & result.Row) & vbCrLf & _
"Terminating Location: " & Range("P" & result.Row) & vbCrLf & _
"Stabling Location: " & Range("Q" & result.Row), Title:="Location Info"

vbCrLf adds the new line, then I added a string to name the information showing, then the column where it's found.

Make sure you edit the message box in both sections.
Amazing, thank you again mate. You seem to be my excel hero.
Appreciate it loads!
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,161
Members
452,615
Latest member
bogeys2birdies

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