Dependent data validation (drop down) with vlookup

hshamdani

New Member
Joined
Jan 12, 2014
Messages
2
Hello folks,
I have a list of students and the classes they are taking (Sheet1) and I have a ledger (Sheet2).

Sheet1:

Student IDStudent NameClassTotal AmountTotal_PaidBalance
101Student Name 1Math150
101Student Name 1Science150
101Student Name 1Geography80
101Student Name 1History80
101Student Name 1P.E.50
101Student Name 1Arts50
102Student Name 2Science100
102Student Name 2Geography100
102Student Name 2History75
102Student Name 2P.E.10
103Student Name 3Math200
103Student Name 3Science250
103Student Name 3Geography100
103Student Name 3History55
103Student Name 3P.E.50
103Student Name 3Arts50
103Student Name 3Biology80
103Student Name 3AP300

<colgroup><col><col><col><col span="3"></colgroup><tbody>
</tbody>

Sheet2:

S_IDS_NameClassDateDebitCredit
101Student Name 1

<colgroup><col><col><col span="4"></colgroup><tbody>
</tbody>

I have put a vlookup function in the ledger (sheet2) where, if i put the student id the student name populates in the next cell. What i need now is a drop down menu in the column next to it with ONLY the names of classes that respective student is taking. And once a transaction is recorded in the ledger that students payment and balance amount needs to be automatically updated on sheet1.
I hope this explained my problem sufficiently. I am new to this so please bear with me. should there be any question please let me know. thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi and welcome to the MrExcel Message Board.

Apologies in advance, this is going to be slightly complicated but I can't think of another way using Data Validation.

You can use different Lists with Data Validation if you can assign a Defined Name to each one. That would mean creating a different Defined Name for each name in your master list. Defined Names can be created using the Formulas--> Defined Names--> Name Manager menu path.

The second problem is that Defined Names cannot contain blanks (and there are some other restrictions). So those will need to be removed.

My proposal is that you have a macro, which will need to be pasted in to a Macro Module that will create all the Defined Names for you. You will need to run the macro every time you make a change to your master name/course list. (It may be possible to automate that if you decide to go with this proposal.)

The second step is to create a Data Validation rule that will remove the blanks from the names and call up the correct list.

Macro code:
Code:
Sub CreateDefinedNames()

    Dim i As Long
    Dim Name As String
    Dim iStart As Long

    With ThisWorkbook.Worksheets("Sheet1")
        For i = 2 To .Cells(.Rows.Count, "B").End(xlUp).Row
            ' First Name
            If .Cells(i, "B").Value <> .Cells(i - 1, "B").Value Then
                Name = .Cells(i, "B").Value
                iStart = i
            End If
            ' Last Name
            If .Cells(i, "B").Value <> .Cells(i + 1, "B").Value Then
                .Range(.Cells(iStart, "C"), .Cells(i, "C")).Name = Replace(Name, " ", "_")
            End If
        Next
    End With

End Sub
The code runs down the list of names in Sheet1.
It notes the first and last row for each name then sets the range to the list of courses.
It also replaces any blanks in the names with underscores (_).

To call up those Defined Names you need to also remove the blanks there as well. So the formula for cell B2 is:
=INDIRECT(SUBSTITUTE(B2," ","_"))

Once you have set up one cell you can fill down that cell to all the required ones.
 
Upvote 0

Forum statistics

Threads
1,215,443
Messages
6,124,890
Members
449,194
Latest member
JayEggleton

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