将奇数分成两个单独的整数

时间:2016-07-05 17:43:55

标签: vba case

我有以下代码。在上一个elseIF我正在用一个公式。请参阅此处的代码:

Select Case GroepAanwezig
        Case 1
              If klas = "T1A2" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A2 & " ) "
                    slbstdperklas = nT1A2
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A2" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A2 & " ) "
                    slbstdperklas = nT2A2
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A3A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3A & " ) "
                    slbstdperklas = nT2A3A
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A3B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3B & " ) "
                    slbstdperklas = nT2A3B
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A4 & " ) "
                    slbstdperklas = nT2A4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3A3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A3 & " ) "
                    slbstdperklas = nT3A3
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A4 & " ) "
                    slbstdperklas = nT3A4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T4A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4A4 & " ) "
                    slbstdperklas = nT4A4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9A & " ) "
                    slbstdperklas = nT1A9A
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9B & " ) "
                    slbstdperklas = nT1A9B
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9C" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9C & " ) "
                    slbstdperklas = nT1A9C
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1K9" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1K9 & " ) "
                    slbstdperklas = nT1K9
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2K3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K3 & " ) "
                    slbstdperklas = nT2K3
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2K4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K4 & " ) "
                    slbstdperklas = nT2K4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1G4A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4A & " ) "
                    slbstdperklas = nT1G4A
              ElseIf klas = "T1G4B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4B & " ) "
                    slbstdperklas = nT1G4B
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2G4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2G4 & " ) "
                    slbstdperklas = nT2G4
              ElseIf klas = "T3G4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3G4 & " ) "
                    slbstdperklas = nT3G4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E3 & " ) "
                    slbstdperklas = nT1E3
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E4 & " ) "
                    slbstdperklas = nT1E4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E3 & " ) "
                    slbstdperklas = nT2E3
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E4 & " ) "
                    slbstdperklas = nT2E4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E3 & " ) "
                    slbstdperklas = nT3E3
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E4 & " ) "
                    slbstdperklas = nT3E4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T4E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4E4 & " ) "
                    slbstdperklas = nT4E4
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              End If

        Case 2

             If klas = "T1A2" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A2 & " ) "
                    slbstdperklas = Int(nT1A2 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A2" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A2 & " ) "
                    slbstdperklas = Int(nT2A2 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A3A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3A & " ) "
                    slbstdperklas = Int(nT2A3A / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A3B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3B & " ) "
                    slbstdperklas = Int(nT2A3B / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A4 & " ) "
                    slbstdperklas = Int(nT2A4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3A3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A3 & " ) "
                    slbstdperklas = Int(nT3A3 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A4 & " ) "
                    slbstdperklas = Int(nT3A4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T4A4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4A4 & " ) "
                    slbstdperklas = Int(nT4A4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9A & " ) "
                    slbstdperklas = Int(nT1A9A / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9B & " ) "
                    slbstdperklas = Int(nT1A9B / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1A9C" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9C & " ) "
                    slbstdperklas = Int(nT1A9C / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1K9" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1K9 & " ) "
                    slbstdperklas = Int(nT1K9 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2K3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K3 & " ) "
                    slbstdperklas = Int(nT2K3 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2K4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K4 & " ) "
                    slbstdperklas = Int(nT2K4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1G4A" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4A & " ) "
                    slbstdperklas = Int(nT1G4A / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1G4B" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4B & " ) "
                    slbstdperklas = Int(nT1G4B / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2G4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2G4 & " ) "
                    slbstdperklas = Int(nT2G4 / GroepAanwezig)
                    sifir = 0

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3G4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3G4 & " ) "
                    slbstdperklas = Int(nT3G4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E3 & " ) "
                    slbstdperklas = Int(nT1E3 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T1E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E4 & " ) "
                    slbstdperklas = Int(nT1E4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E3 & " ) "
                    slbstdperklas = Int(nT2E3 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T2E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E4 & " ) "
                    slbstdperklas = Int(nT2E4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3E3" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E3 & " ) "
                    slbstdperklas = Int(nT3E3 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T3E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E4 & " ) "
                    slbstdperklas = Int(nT3E4 / GroepAanwezig)

                    Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
              ElseIf klas = "T4E4" Then
                    ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4E4 & " ) "
                    slbstdperklas = Int(nT4E4 / GroepAanwezig)


                    rest = nT4E4 - slbstdperklas


                    Sheets("StdntKlas").Cells(i, 3 + j).Value = rest
              End If

        End Select

Case 1功能很棒,没有问题。对于Case 2我继续用奇数编号。我怎样才能将例如31的数字分成15和16。

让我们说有一个可以解决这个问题的公式,我不知道如何使用第一个数字15后面的数字16作为单独的数字。 所以我进入一个牢房



<table border=1><tr><td>T4E4</td><td>15</td></tr><tr><td>T4E4</td><td>16</td></tr></table>
&#13;
&#13;
&#13;

我希望我提出了我的问题

1 个答案:

答案 0 :(得分:0)

我想我已经解决了,有人可以检查一下。有没有办法缩短这段代码?

Dim GroepenCol As New Collection

'GroepenCol.Add nT9N4, "T9N4"
GroepenCol.Add nT1A2, "T1A2"
GroepenCol.Add nT2A2, "T2A2"
GroepenCol.Add nT2A3A, "T2A3A"
GroepenCol.Add nT2A3B, "T2A3B"
GroepenCol.Add nT3A3, "T3A3"
GroepenCol.Add nT3A4, "T3A4"
GroepenCol.Add nT4A4, "T4A4"
GroepenCol.Add nT1A9A, "T1A9A"
GroepenCol.Add nT1A9B, "T1A9B"
GroepenCol.Add nT1A9C, "T1A9C"
GroepenCol.Add nT1K9, "T1K9"
GroepenCol.Add nT2K3, "T2K3"
GroepenCol.Add nT2K4, "T2K4"
GroepenCol.Add nT1G4A, "T1G4A"
GroepenCol.Add nT1G4B, "T1G4B"
GroepenCol.Add nT2G4, "T2G4"
GroepenCol.Add nT3G4, "T3G4"

GroepenCol.Add nT1E3, "T1E3"
GroepenCol.Add nT1E4, "T1E4"
GroepenCol.Add nT2E3, "T2E3"
GroepenCol.Add nT2E4, "T2E4"
GroepenCol.Add nT3E3, "T3E3"
GroepenCol.Add nT3E4, "T3E4"
GroepenCol.Add nT4E4, "T4E4"

lastRtot = Sheets("totaallijst").Cells.SpecialCells(xlCellTypeLastCell).row


For r = 1 To lastRtot
    If Sheets("totaallijst").Cells(r, 9).Value = "" Then
      Sheets("totaallijst").Cells(r, 9).Value = Sheets("totaallijst").Cells(r, 8).Value
      Sheets("totaallijst").Cells(r, 8).Value = ""
    End If
Next r


ThisWorkbook.Sheets("StdntKlas").Activate
lastRow = Sheets("SLB").Cells.SpecialCells(xlCellTypeLastCell).row
  For i = 2 To lastRow 'uit de eerste cel in kolom 1 wordt de x klas gezocht over a1:e10 de klas die terugkrijgt is de aantal voorkomende x
    lastCol = Sheets("SLB").Cells(i, Columns.Count).End(xlToLeft).Column
    'MsgBox lastRow & " i: " & i 'last row 29 i is correct
    For j = 2 To lastCol


        klas = Sheets("SLB").Cells(i, j).Value

        Sheets("StdntKlas").Cells(i, j).Value = klas

        Sheets("StdntKlas").Cells(1, 1).Value = "SLB-ers"
        slbers = Sheets("SLB").Cells(i, 1).Value
        Sheets("StdntKlas").Cells(i, 1).Value = slbers

        rn_slb = ThisWorkbook.Sheets("SLB").Cells.SpecialCells(xlCellTypeLastCell).row
        GroepAanwezig = Application.WorksheetFunction.CountIf(Sheets("SLB").Range("B2:D29" & rn_slb), klas)

        Sheets("StdntKlas").Cells(i, 3 + j).Value = GroepAanwezig

        Dim arrOutput(2)
        Select Case GroepAanwezig
            Case 1
                  If klas = "T1A2" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A2 & " ) "
                        slbstdperklas = nT1A2
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2A2" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A2 & " ) "
                        slbstdperklas = nT2A2
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2A3A" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3A & " ) "
                        slbstdperklas = nT2A3A
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2A3B" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A3B & " ) "
                        slbstdperklas = nT2A3B
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2A4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2A4 & " ) "
                        slbstdperklas = nT2A4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T3A3" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A3 & " ) "
                        slbstdperklas = nT3A3
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T3A4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3A4 & " ) "
                        slbstdperklas = nT3A4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T4A4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4A4 & " ) "
                        slbstdperklas = nT4A4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1A9A" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9A & " ) "
                        slbstdperklas = nT1A9A
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1A9B" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9B & " ) "
                        slbstdperklas = nT1A9B
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1A9C" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1A9C & " ) "
                        slbstdperklas = nT1A9C
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1K9" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1K9 & " ) "
                        slbstdperklas = nT1K9
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2K3" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K3 & " ) "
                        slbstdperklas = nT2K3
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2K4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2K4 & " ) "
                        slbstdperklas = nT2K4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1G4A" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4A & " ) "
                        slbstdperklas = nT1G4A
                  ElseIf klas = "T1G4B" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1G4B & " ) "
                        slbstdperklas = nT1G4B
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2G4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2G4 & " ) "
                        slbstdperklas = nT2G4
                  ElseIf klas = "T3G4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3G4 & " ) "
                        slbstdperklas = nT3G4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1E3" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E3 & " ) "
                        slbstdperklas = nT1E3
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T1E4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT1E4 & " ) "
                        slbstdperklas = nT1E4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2E3" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E3 & " ) "
                        slbstdperklas = nT2E3
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T2E4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT2E4 & " ) "
                        slbstdperklas = nT2E4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T3E3" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E3 & " ) "
                        slbstdperklas = nT3E3
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T3E4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT3E4 & " ) "
                        slbstdperklas = nT3E4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  ElseIf klas = "T4E4" Then
                        ThisWorkbook.Sheets("StdntKlas").Cells(i, j).Value = klas & " ( " & nT4E4 & " ) "
                        slbstdperklas = nT4E4
                        Sheets("StdntKlas").Cells(i, 3 + j).Value = slbstdperklas
                  End If

            Case 2
                    arrOutput(0) = Int(GroepenCol(klas) / GroepAanwezig)
                    arrOutput(1) = GroepenCol(klas) - arrOutput(0)
                    arrOutput(2) = 0
               ' ====== ALGO START
                    ' The following calculate the number of times salk appears before the current cell
                    'Depends on the ROWS since you CAN'T use a range which is not continuous with COUNTIF!
                    Select Case i
                        Case 1
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B1" & ":" & Cells(i, j).Address), klas)
                        Case 2
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B2" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D1"), klas)
                        Case 3
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B3" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D2"), klas)
                        Case 4
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B4" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D3"), klas)
                        Case 5
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B5" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D4"), klas)
                        Case 6
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B6" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D5"), klas)
                        Case 7
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B7" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D6"), klas)
                        Case 8
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B8" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D7"), klas)
                        Case 9
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B9" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D8"), klas)
                        Case 10
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B10" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D9"), klas)
                        Case 11
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B11" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D10"), klas)
                        Case 12
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B12" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D11"), klas)
                        Case 13
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B13" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D12"), klas)
                        Case 14
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B14" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D13"), klas)
                        Case 15
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B15" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D14"), klas)
                        Case 16
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B16" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D15"), klas)
                        Case 17
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B17" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D16"), klas)
                        Case 18
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B18" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D17"), klas)
                        Case 19
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B19" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D18"), klas)
                        Case 20
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B20" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D19"), klas)
                        Case 21
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B21" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D20"), klas)
                        Case 22
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B22" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D21"), klas)
                        Case 23
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B23" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D22"), klas)
                        Case 24
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B24" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D23"), klas)
                        Case 25
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B25" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D24"), klas)
                        Case 26
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B26" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D25"), klas)
                        Case 27
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B27" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D26"), klas)
                        Case 28
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B28" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D27"), klas)
                        Case 29
                            GroepAanwezigCurr = WorksheetFunction.CountIf(Worksheets("SLB").Range("B29" & ":" & Cells(i, j).Address), klas) + WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D28"), klas)

                        Case Else       ' Should not happen
                            MsgBox "Error, out of range"
                    End Select
                    GroepAanwezigCurr = GroepAanwezigCurr - 1    ' Minus 1 because the current cell would be counted
                    ' ===== ALGO END
                    Sheets("StdntKlas").Cells(i, j).Value = klas & " (" & arrOutput(GroepAanwezigCurr) & ")"
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = arrOutput(GroepAanwezigCurr)
                    slbstdperklas = arrOutput(GroepAanwezigCurr)
                  Case Else
                    'MsgBox "Error"
            End Select




    Next j
Next i