+ Reply to Thread
Results 1 to 10 of 10

Setting up a grading matrix, vlookup doesn't help

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Setting up a grading matrix, vlookup doesn't help

    Hi there,
    I 'foolishly' offered to help a local school set up some standard forms etc! All have gone OK except for this one which is driving me nuts. I have tried vlookups, if functions etc, just can't get it working... I suspect it needs some VBA...

    I have attached what I am trying to achieve. Input tab has the data, basically a set of grades for students, one grade at age 8, the other grade at age 11. I am trying to present this in a matrix, see Output tab. I want to automatically place the student name(s) in the cell that corresponds to their two grades. I have manually done the first 6 names.
    teacher grading tool.xlsx

    Your assistance would be much appreciated.
    Thanks
    Last edited by Rossg59b; 12-06-2013 at 12:58 PM. Reason: SOLVED

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Setting up a grading matrix, vlookup doesn't help

    Hi,

    I can only see three manually-entered results, though I think I get the picture.

    However, you don't mention what the results should be if two or more students have identical grades. My first thought was comma-separated in the same cell, though, above a certain number, this could become quite ungainly, not to mention the fact that it would then make a formula-based solution problematic and therefore require some VBA.

    Please clarify.

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Registered User
    Join Date
    12-05-2013
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Setting up a grading matrix, vlookup doesn't help

    Hi,

    thanks for responding. Yes if students have the same results at both age groups, then it would be great if their names appear in the same cell, comma separated. There aren't too many students per class, so it shouldn't become too ungainly.

    I have been through all sorts of formula based approaches and I think that VBA is the way to solve this - and is beyond me!

    Many thanks

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Setting up a grading matrix, vlookup doesn't help

    Please try:
    Function ListStudents(rStudents As Range, rGrades1 As Range, vGrade1, rGrades2 As Range, vGrade2, Optional sDelimiter As String = ",") As String
       Dim n                           As Long
       Dim stemp                       As String
       For n = 1 To rStudents.Count
          If LCase(rGrades1(n).Value) = LCase(vGrade1) Then
             If LCase(rGrades2(n).Value) = LCase(vGrade2) Then
                stemp = stemp & sDelimiter & rStudents(n).Value
             End If
          End If
       Next n
       If Len(stemp) > 0 Then ListStudents = Mid$(stemp, Len(sDelimiter) + 1)
    
    End Function
    Enter in D9: =ListStudents(Input!$B$4:$B$25,Input!$C$4:$C$25,D$20,Input!$D$4:$D$25,$C9)
    and fill the table

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Setting up a grading matrix, vlookup doesn't help

    Or another approach:

    Sub foo()
    Dim lSourceRow As Long, lPasteRow As Long, lPasteCol As Long
    Dim stPupil As String, stOutput As String
    For lSourceRow = 4 To 25
        stPupil = Sheets("Input").Cells(lSourceRow, 2).Value
        lPasteRow = 8 + WorksheetFunction.Match(Sheets("Input").Cells(lSourceRow, 4).Value, Worksheets("Output").Range("C9:C19"), 0)
        lPasteCol = 3 + WorksheetFunction.Match(Sheets("Input").Cells(lSourceRow, 3).Value, Worksheets("Output").Range("D20:L20"), 0)
        If Worksheets("Output").Cells(lPasteRow, lPasteCol).Value = "" Then
            stOutput = stPupil
        Else
            stOutput = Worksheets("Output").Cells(lPasteRow, lPasteCol).Value & ", " & stPupil
        End If
       Worksheets("Output").Cells(lPasteRow, lPasteCol).Value = stOutput
    Next lSourceRow
    End Sub
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: Setting up a grading matrix, vlookup doesn't help

    I was going to have a go at this but the competition was just too quick.

    For my own benefit, I put the code into the workbook so I could see how it worked. The result is attached.

    One question for OllyXLS: your routine seems to double up in some instances, although not all. Why is that?

    Regards, TMS
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Setting up a grading matrix, vlookup doesn't help

    Quote Originally Posted by TMShucks View Post
    One question for OllyXLS: your routine seems to double up in some instances, although not all. Why is that?
    Ah, looks like you didn't delete the example results which were pre-filled in the output sheet. Apologies - I should have set my routine to clear the output range first.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: Setting up a grading matrix, vlookup doesn't help

    @Rossg59b: Thanks for the rep.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: Setting up a grading matrix, vlookup doesn't help

    @OllyXLS: that's exactly right. I copied the sheet and renamed it so that a) I had the structure and b) I could compare the results.

    Regards, TMS

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: Setting up a grading matrix, vlookup doesn't help

    Final option (maybe) using arrays:

    Sub TMS()
    
    Dim shIn As Worksheet: Set shIn = Sheets("Input")
    Dim shOut As Worksheet: Set shOut = Sheets("TMS")
    Dim rIn As Range, rOut As Range
    Dim vIn, vInR, vInC, vOut
    Dim i As Long
    Dim sPupil As String, vGat8, vGat11
    Dim lRIndex As Long, lCIndex As Long
    Dim awf As WorksheetFunction: Set awf = WorksheetFunction
    
    Application.ScreenUpdating = True
    
    ' store the data from the input sheet
    With shIn
        vIn = .Range(.Range("B4"), _
                     .Range("B4").End(xlDown)) _
              .Resize(, 3)
    End With
    
    ' set the range(s) from the output sheet
    With shOut
        ' use for lookup
        Set rIn = .Range(.Range("C9"), _
                         .Range("C9").End(xlDown))
        ' where the output is going
        Set rOut = rIn.Offset(0, 1).Resize(, rIn.Rows.Count)
    End With
    
    vInR = awf.Transpose(rIn)   ' row lookup, Grade at 11
    vInC = awf.Transpose(rIn)   ' just to get the size
    ' column lookup, Grade at 8 (reverse row values)
    For i = LBound(vInR) To UBound(vInR)
        vInC(i) = vInR(UBound(vInR) - i + 1)
    Next i
    
    ' prepare the output matrix
    ReDim vOut(LBound(vInR) To UBound(vInR), _
               LBound(vInC) To UBound(vInC))
    
    ' loop through the input data and store in output matrix
    For i = LBound(vIn, 1) To UBound(vIn, 1)
        sPupil = vIn(i, 1): vGat8 = vIn(i, 2): vGat11 = vIn(i, 3)
        lRIndex = awf.Match(vGat11, vInR, 0)
        lCIndex = awf.Match(vGat8, vInC, 0)
        If vOut(lRIndex, lCIndex) = "" Then
            vOut(lRIndex, lCIndex) = sPupil
        Else
            vOut(lRIndex, lCIndex) = _
                vOut(lRIndex, lCIndex) & ", " & _
                sPupil
        End If
    Next 'i
    
    ' clear/format the output range
    With rOut
        .ClearContents
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlTop
        .WrapText = True
    End With
    
    ' move output matrix to worksheet
    rOut = vOut
    
    Application.ScreenUpdating = True
    
    End Sub

    Regards, TMS
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-12-2013, 04:14 PM
  2. macros disable error - security setting doesn't fix
    By jayron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2007, 07:23 PM
  3. [SOLVED] student needing help w/vlookup function grading criteria
    By Julie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-21-2005, 09:05 AM
  4. Object doesn't support current locale setting: 'setlocale'
    By Martin Eckart in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2005, 05:06 AM
  5. Fit Selection Setting Doesn't Hold
    By Brett in forum Excel General
    Replies: 1
    Last Post: 04-20-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1