1

I need some help with a formula i am trying to make for a mark book. I have a work book, with a sheet labelled "Master" that contains students unique reference numbers in col A2, their names B2/C2 and then the four subjects they study in col D2,E2,F2 and G2. I also then have separate sheets for each individual subject.

I would like to look up the subjects on the master sheet (in the four columns) and if "Maths" is a subject a student takes in one of those columns, i would like the corresponding student name and reference from that row to be copied and pasted into the sheet "Maths" so further information can be entered regarding that subject/student and class.

I have tried working with a IF and MATCH formula but it seems to get quite complex, as I have over 400 students who each have four subjects, and the subjects can appear in anyone of the four subject columns.

Any suggestions?

TIA!

Bryony309
  • 11
  • 1
  • 1
  • 2

2 Answers2

3

There are two possible solutions, the easiest is:

In the Math sheet, insert this:

[cell B2]

=IF(Sheet1!D2="Math";Sheet1!B2;IF(Sheet1!E2="Math";Sheet1!B2;IF(Sheet1!F2="Math";Sheet1!B2;IF(Sheet1!G2="Math";Sheet1!B2;""))))

[cell C2]

=IF(Sheet1!D2="Math";Sheet1!C2;IF(Sheet1!E2="Math";Sheet1!C2;IF(Sheet1!F2="Math";Sheet1!C2;IF(Sheet1!G2="Math";Sheet1!B2;""))))

And drag them down trough the document ...


Here is a sample test I made:

Students sheet:

-------------
1001    Toni    Almeida     Math        Portuguese  Programming     Another
1002    David   P           Portuguese  French      Programming     Another
1003    Neil    C           Math        Portuguese  Programming     Another
1004    James   H           Portuguese  French      Programming     Another
-------------

Result (Math sheet):

-------------
1001    Toni    Almeida 
1002    
1003    Neil    C   
1004    
-------------

You can also create a query:

Note: This works at least in Google Spreadsheet, I don't have MS Office to test this in Excel.

=query(B2:G5;"select B,C where D='Math'OR E='Math' OR F='Math' OR G='Math'";1)

Result:

-------------
1001    Toni    Almeida 
1003    Neil    C   
-------------
António Almeida
  • 9,620
  • 8
  • 59
  • 66
  • If this formula is entered into the math sheet there is no data in cell d2 on the math sheet for the formula to look at, the cell is empty. Should i enter it on the master sheet? – Bryony309 Feb 26 '14 at 09:36
  • Actually, all the references `B2`, `C2`, `D2`, `E2`, `F2`, `G2` ... Are for the first sheet, the students sheet. – António Almeida Feb 26 '14 at 09:42
2

The easiest solution would be to filter columns D2,E2,F2,G2 then copy/paste results to different worksheets. If you want this to be done autmatically, you'll need to write a macro. Regards,

edit: Move your data to a sheet called "Main" and alt+F11 to open visual basic editor, insert>modules, select module and paste this code below and save. alt+F8 to open macros and run ProcessList Macro, it will create your sheets automatically.

Sub ProcessList()
Dim course As String
Dim studentID As String
Dim studentName As String
Dim studentSurname As String

Application.DisplayAlerts = False
For Each w In Worksheets
    If Not w.Name = "Main" Then
        w.Delete
    End If
Next
Application.DisplayAlerts = True

i = 0
While Not Worksheets("Main").Cells(2 + i, 1) = ""
i = i + 1
Wend
studentcount = i

For i = 0 To studentcount - 1
    studentID = Worksheets("Main").Cells(2 + i, 1).Value
    studentName = Worksheets("Main").Cells(2 + i, 2).Value
    studentSurname = Worksheets("Main").Cells(2 + i, 3).Value
    For j = 0 To 3
        course = Worksheets("Main").Cells(2 + i, 4 + j).Value
        If Not course = "" Then
        Call checkcourse(course)
        Call insertStudentData(course, studentID, studentName, studentSurname)
        End If
    Next j
Next i

End Sub

Sub checkcourse(course)
found = False
For Each w In Worksheets
    If w.Name = course Then
        found = True
    End If
Next
If found = False Then
        Worksheets.Add().Name = course
End If

End Sub

Sub insertStudentData(wsName As String, studentID, studentName, studentSurname)
i = 0
While Not Worksheets(wsName).Cells(2 + i, 1) = ""
    i = i + 1
Wend
Worksheets(wsName).Cells(2 + i, 1).Value2 = studentID
Worksheets(wsName).Cells(2 + i, 2).Value2 = studentName
Worksheets(wsName).Cells(2 + i, 3).Value2 = studentSurname
End Sub
  • Yes, I do need it to be done automatically, so if a new student row and set of subjects is added that would then copy their names into the appropriate subjects sheets. I have not really used Macros before much, would it be complicated to set up? – Bryony309 Feb 26 '14 at 09:09
  • I have edited it. This should create your sheets automatically. – Trevize Daneel Feb 26 '14 at 10:34
  • This is amazing!!! It found a bug though "Next If found = False Then Worksheets.Add().Name = course End If" – Bryony309 Feb 26 '14 at 10:51
  • And also only added the first student in the data section to the four subjects sheets he is in – Bryony309 Feb 26 '14 at 10:53
  • I have fixed it a bit, it should work now. Also please skip the first row on "Main" sheet as I thought maybe you could put headers there. If you cant run it, send me your mail address and I'll send the sheet over – Trevize Daneel Feb 26 '14 at 11:04
  • Seems to run but not pick up everything. Can't see how to private msg on her for the email address though? (Sorry new!) What would happen with this if new students were added to the bottom, would the macro need to be re run to add them onto the sheets? And in doing that, would it remove other data stored on the subject sheets? Twenty questions or what... :-) – Bryony309 Feb 26 '14 at 11:33
  • Well you can't send private messages here but type your email in your profile. You'll need to run the macro each time you need to update the sheets. All other sheets will be removed. You can improve this macro or use it to just generate related course worksheets & then copy/paste to another styled workbook for use. It should pick everything unless you have empty data on studentid colum (A) on Main sheet. – Trevize Daneel Feb 26 '14 at 12:06
  • Thank you for all your help. I don't think i can use this macro then, as the subject sheets are going to have additional information in, and cant be wiped. Thank you anyway for all your help. – Bryony309 Feb 26 '14 at 12:29
  • No problem, but mind that macro is your sole option. Also you can modify this macro to your needs. For ex: remove the line "w.Delete" and other sheets wont be removed. – Trevize Daneel Feb 26 '14 at 13:08