在for循环中返回不同的值

时间:2016-07-03 15:07:28

标签: vba excel-vba for-loop excel

我在VBA中遇到了一个奇怪的问题。我无法解决这种情况

我有以下代码。

lastRow = Sheets("SLB").Cells.SpecialCells(xlCellTypeLastCell).row
  For i = 2 To lastRow 
    lastCol = Sheets("SLB").Cells(i, Columns.Count).End(xlToLeft).Column
    For j = 2 To lastCol
        klas = Sheets("SLB").Cells(i, j).Value
        GroepAanwezig = WorksheetFunction.CountIf(Worksheets("SLB").Range("B1:D29"), klas)
        slbers = Sheets("SLB").Cells(i, 1).Value

        If InStr(nshow, klas) = 0 Then
        GroepID(t) = klas
        nshow = nshow & " " & GroepAanwezig & " " & t & " " & GroepID(t) & vbCrLf
        t = t + 1
        End If

        'Ook tellen hoeveel klas een docent heeft
        countCol = Sheets("SLB").Cells(i, Columns.Count).End(xlToLeft).Column
        lastcolumn = countCol - 1

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

Select Case GroepAanwezig
               Case 1
                    Sheets("StdntKlas").Cells(i, j).Value = klas & " (" & GroepenCol(klas) & ")"
                    Sheets("StdntKlas").Cells(i, 3 + j).Value = GroepenCol(klas)
                    slbstdperklas = GroepenCol(klas)
                     'over here it returns a different value i then before, this i stops at 20 how come?                  
                Case 2

                  'testing

end Select
    next j
next i

看代码,我得到了评论不同的值作为回报。 :( ...

请帮帮我......

0 个答案:

没有答案