See if this works.
Two helper columns have been used , columns J and K.
Cells J2 through J25 (24 cells since you have said the number of courses is 24) have a multi-cell array formula :
which is entered using CTRL SHIFT ENTER.
Cell K2 has the following formula :
This is a single-cell array formula , entered using CTRL SHIFT ENTER. Copy this formula down till K25 (24 cells).
Now , a named range Courses_DV has been defined , with the following formula :
This basically excludes the blank cells from the subjects list in column K.
Use this named range for the Data Validation list in cell D18.
See the attached file.