lookup a list based on a cell and return a choice of values from the list

Cathmac801

New Member
Joined
Apr 23, 2014
Messages
20
Hi Folks, I am working on a spreadsheet that has 2 tabs "Master sheet" "Rule type"

On the Rule Type sheet there is a column called 'Location' (this is a number and the same number can show up multiple times), there is also a column called 'Rule Type' - for each location there are multiple rule types (this sheet has c1500 rows)

On the Master sheet there are multiple columns, one is called 'Location' and another is called 'rule type' - i want to set up the 'rule type' cell so that when you click on it only the rule type options for the specific location are available (i.e. a drop down list).

I have seen some examples on my research but can't seem to find exactly what i'm looking for, any help much appreciated.

This is an example of the 'Rule Type' sheet

LocationRule Type
1XRJ-111
1RZ2-156
13% annually
7XTP-876
73% annually
954WEQ-456
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of both sheets, "Master sheet" and "Rule type" sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Hi Folks, I am working on a spreadsheet that has 2 tabs "Master sheet" "Rule type"

On the Rule Type sheet there is a column called 'Location' (this is a number and the same number can show up multiple times), there is also a column called 'Rule Type' - for each location there are multiple rule types (this sheet has c1500 rows)

On the Master sheet there are multiple columns, one is called 'Location' and another is called 'rule type' - i want to set up the 'rule type' cell so that when you click on it only the rule type options for the specific location are available (i.e. a drop down list).

I have seen some examples on my research but can't seem to find exactly what i'm looking for, any help much appreciated.

This is an example of the 'Rule Type' sheet

LocationRule Type
1XRJ-111
1RZ2-156
13% annually
7XTP-876
73% annually
954WEQ-456
MrExcelQ300721.xlsx
ABC
1NameLocationRule Type
2Joe Bloggs9
3Jack Sprat11
4Pauline Murphy33
5Catherine Enright31
Master Sheet


MrExcelQ300721.xlsx
AB
1LocationRule Type
29XT39Y-9
39XT23-9
49IBS100-9
59XT42E-9
69XT31X12-9
79XT26X10-9
89XT45E-9
99XT29E-9
109XT43E-9
119XT9-9
1211XT26X4-11
1311BE-11
1411XT26-11
1511XT26X4Y-11
1611IBS100-11
1711XT52-11
1831IBS100-31
1931XT6-31
2031BE-31
2131XD98M7-31
2231XT9-31
2331XD98M11-31
2431XD98M9-31
2531XD98M5-31
2631XD98M1-31
2731XD98M10-31
2833BE-33
2933XD97-33
3033XD95M1-33
3133XT6B-33
3233XT6-33
3333XD103M1-33
3433XT6BY-33
3533XT6BX6-33
3633XT6X3-33
3733XT6Z7-33
3833XT6BX9-33
3933XT6X7-33
4033IBS100-33
4133XT6X6-33
4233XT6X1-33
4333XT6BX1-33
4433XT6XZ12-33
4533XT6X5-33
4633XT6Z5-33
4733XT6X11-33
4833XT6X12-33
4933XT6X8-33
5033XT6X4-33
5133XT6BX10-33
Rule Type


MrExcelQ300721.xlsx
AB
1831IBS100-31
1931XT6-31
2031BE-31
2131XD98M7-31
2231XT9-31
2331XD98M11-31
2431XD98M9-31
2531XD98M5-31
2631XD98M1-31
2731XD98M10-31
2833BE-33
2933XD97-33
3033XD95M1-33
3133XT6B-33
3233XT6-33
3333XD103M1-33
3433XT6BY-33
3533XT6BX6-33
3633XT6X3-33
3733XT6Z7-33
3833XT6BX9-33
3933XT6X7-33
4033IBS100-33
4133XT6X6-33
4233XT6X1-33
4333XT6BX1-33
4433XT6XZ12-33
Rule Type


What i would like to do is:
On Master sheet in cell C2 - i want the formula to look at cell B2 and then go to the 'rule type' sheet and find what is in B2 from column A and give me a list in C2 on the master of what is in column B on the rule type sheet.
So in this example cell C2 would have a list that would read (below) and the user would be able to select the rule they wanted.
XT39Y-9
XT23-9
IBS100-9
XT42E-9
XT31X12-9
XT26X10-9
XT45E-9
XT29E-9
XT43E-9
XT9-9
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Master sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Double click on any cell in column C.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge < 1 Then Exit Sub
    If Target.Column <> 3 Then Exit Sub
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, rng As Range, val As String
    Set srcWS = Sheets("Rule Type")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Cells(1).CurrentRegion.AutoFilter 1, Target.Offset(, -1).Value
        For Each rng In srcWS.Range("B2", srcWS.Range("B" & srcWS.Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
            If val = "" Then val = rng Else val = val & "," & rng
        Next rng
    End With
    With Target.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Application.Transpose(val)
    End With
    val = ""
    srcWS.Cells(1).AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your Master sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Double click on any cell in column C.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge < 1 Then Exit Sub
    If Target.Column <> 3 Then Exit Sub
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, rng As Range, val As String
    Set srcWS = Sheets("Rule Type")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Cells(1).CurrentRegion.AutoFilter 1, Target.Offset(, -1).Value
        For Each rng In srcWS.Range("B2", srcWS.Range("B" & srcWS.Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
            If val = "" Then val = rng Else val = val & "," & rng
        Next rng
    End With
    With Target.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Application.Transpose(val)
    End With
    val = ""
    srcWS.Cells(1).AutoFilter
    Application.ScreenUpdating = True
End Sub
@mumps, sincere apologies for not getting back to you on this sooner. my developer was broken and i was waiting on a new laptop. I don't know what to say, this is absolute genius. Thank you so much, it has saved me so much time and looks to be exactly what i need. very much appreciated.
 
Upvote 0
@mumps, sincere apologies for not getting back to you on this sooner. my developer was broken and i was waiting on a new laptop. I don't know what to say, this is absolute genius. Thank you so much, it has saved me so much time and looks to be exactly what i need. very much appreciated.
@mumps - sorry i am very new to vba - i had to move the location of my data around on my master sheet so now 'location' has moved starting in cell H4 (previously B2) and the 'rule type' where i need the drop down is in colum O - starting in O4 (previously C2)
I tried to change the code to H4 and column H but its not working for me now.
Would you be able to point out where i am going wrong please?

Thanks for your help
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge < 1 Then Exit Sub
    If Target.Column <> 15 Then Exit Sub
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, rng As Range, val As String
    Set srcWS = Sheets("Rule Type")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Cells(1).CurrentRegion.AutoFilter 1, Target.Offset(, -7).Value
        For Each rng In .Range("B2", .Range("B" & .Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
            If val = "" Then val = rng Else val = val & "," & rng
        Next rng
    End With
    With Target.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Application.Transpose(val)
    End With
    val = ""
    srcWS.Cells(1).AutoFilter
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge < 1 Then Exit Sub
    If Target.Column <> 15 Then Exit Sub
    Application.ScreenUpdating = False
    Dim LastRow As Long, srcWS As Worksheet, rng As Range, val As String
    Set srcWS = Sheets("Rule Type")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With srcWS
        .Cells(1).CurrentRegion.AutoFilter 1, Target.Offset(, -7).Value
        For Each rng In .Range("B2", .Range("B" & .Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
            If val = "" Then val = rng Else val = val & "," & rng
        Next rng
    End With
    With Target.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Application.Transpose(val)
    End With
    val = ""
    srcWS.Cells(1).AutoFilter
    Application.ScreenUpdating = True
End Sub
thanks @mumps very helpful :)
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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