Forum Discussion

Sotannde Abiodun Kabir's avatar
Sotannde Abiodun Kabir
Copper Contributor
Dec 04, 2017
Solved

Generating results...

Hello, I want to automate Students results generation with excel VBA. I designed the result template on a worksheet and broadsheet on another sheet (attached here). I need vba codes to print the results of all students automatically with just a click.
Thanks.
  • Hi Sotannde,

     

    please find attached my solution. I used Index/Match to populate Pupil's Progress Report. To enable this, I added a  concatenation line in row 5 to combine area and subject, and used this concatenation as the lookup item in the formula. 

     

    I have also added a macro to loop the list of students and print Progress Reports for each student after populating it with the next student's name. Here is the text of the macro:

     

    Sub print_all_reports()

        Dim vaStudentName As Variant
        Dim i As Integer
        Dim rRptStudentName As Range
       
        Set rRptStudentName = Range("rptStudentName")

        vaStudentName = Range("dataStudentName")
       
        For i = LBound(vaStudentName, 1) To UBound(vaStudentName)
           
            If Len(Trim(vaStudentName(i, 1))) Then
                rRptStudentName = Trim(vaStudentName(i, 1))
                With ActiveSheet
                    .Calculate
                    .PrintOut
                End With
            End If
        Next i

    End Sub

     

    Please be aware that the macro will send printed pages straight to your printer unless you select 'Save to pdf'.

     

    Hope this helps

    Yury

     

2 Replies

  • Yury Tokarev's avatar
    Yury Tokarev
    Steel Contributor

    Hi Sotannde,

     

    please find attached my solution. I used Index/Match to populate Pupil's Progress Report. To enable this, I added a  concatenation line in row 5 to combine area and subject, and used this concatenation as the lookup item in the formula. 

     

    I have also added a macro to loop the list of students and print Progress Reports for each student after populating it with the next student's name. Here is the text of the macro:

     

    Sub print_all_reports()

        Dim vaStudentName As Variant
        Dim i As Integer
        Dim rRptStudentName As Range
       
        Set rRptStudentName = Range("rptStudentName")

        vaStudentName = Range("dataStudentName")
       
        For i = LBound(vaStudentName, 1) To UBound(vaStudentName)
           
            If Len(Trim(vaStudentName(i, 1))) Then
                rRptStudentName = Trim(vaStudentName(i, 1))
                With ActiveSheet
                    .Calculate
                    .PrintOut
                End With
            End If
        Next i

    End Sub

     

    Please be aware that the macro will send printed pages straight to your printer unless you select 'Save to pdf'.

     

    Hope this helps

    Yury