Need formula or code to filter student information based on subjects marks

I have organized a formal file and I want to apply a code or formula, to it. implementing the filtering process.

Just a quick review, I want to construct a table as shown in sheet (P1) of the attached file to collect and store  all the students who got marks less than 50 in the first and the second semesters. The student record is in sheet (P2) of the attached file and the semester marks are explained in the collared ranges, range M7:Z111 for semester 1 and range AB7:AO111 for semester 2. When filtering is done ;
- I need the student name, subject, stage, and semester shown in the second attempt students table.
- neglecting bank cells but taking into consideration in the filtering process they may be contained data in the future.
- The number of students is variable, it could be 111 students or less.
- I need to draw a border around the dedicated row when a student adds to the table of P1.
- The organization of cells in the attached file is from Right to left direction.
- Is it possible to dynamically resize the table of P1 based on the size of the row data?
- can I copy the constructed table into another excel file in the future?

I appreciate too much your efforts and many thanks in advance.

0 Replies