早些时候我问了一个问题,我无法得到正确的答案。我想我无法正确表达自己。这是我面临的问题:

Sub organize()

    Dim GroupID(1 To 30) As String
    Dim GroupAanwezig As Long
    Dim class As String
    Dim i, j, t, totally, countCol As Integer
    Dim GroupenCol As New Collection

    i = 1
    t = 1

    rn_totallist = Worksheets("totallist").Cells.SpecialCells(xlCellTypeLastCell).Row
    nxA_9N4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_9N4")

    nxA_1A2A = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1A2A")
    nxA_1A2B = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1A2B")
    nxA_2A2 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_2A2")

    nxA_2A3 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_2A3")
    nxA_3A3 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_3A3")

    nxA_1B4A = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1B4A")
    nxA_1B4B = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1B4B")
    nxA_1B4C = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1B4C")
    nxA_1B4D = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1B4D")

    nxA_2G4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_2G4")
    nxA_3G4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_3G4")
    nxA_4G4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_4G4")

    nxA_2A4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_2A4")
    nxA_3A4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_3A4")
    nxA_4A4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_4A4")

    nxA_1E3 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1E3")
    nxA_1E4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_1E4")

    nxA_2E4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_2E4")
    nxA_3e3 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_3E3")
    nxA_3e4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_3E4")
    nxA_4e4 = Application.WorksheetFunction.CountIf(Sheets("totallist").Range("G2:G" & rn_totallist), "xA_4E4")

    totalstd = nxA_9N4 + nxA_1A2A + nxA_1A2B + nxA_2A2 + nxA_2A3 + nxA_3A3 + nxA_1B4A + nxA_1B4B + nxA_1B4C + nxA_1B4D + nxA_2G4 + nxA_3G4 + nxA_4G4 + nxA_2A4 + nxA_3A4 + nxA_4A4 + nxA_1E3 + nxA_1E4 + nxA_2E4 + nxA_3e3 + nxA_3e4 + nxA_4e4

     GroupenCol.Add nxA_9N4
     GroupenCol.Add nxA_1A2A
     GroupenCol.Add nxA_1A2B
     GroupenCol.Add nxA_2A2

     GroupenCol.Add nxA_2A3
     GroupenCol.Add nxA_3A3

     GroupenCol.Add nxA_1B4A
     GroupenCol.Add nxA_1B4B
     GroupenCol.Add nxA_1B4C
     GroupenCol.Add nxA_1B4D

     GroupenCol.Add nxA_2G4
     GroupenCol.Add nxA_3G4
     GroupenCol.Add nxA_4G4

     GroupenCol.Add nxA_2A4
     GroupenCol.Add nxA_3A4
     GroupenCol.Add nxA_4A4

     GroupenCol.Add nxA_1E3
     GroupenCol.Add nxA_1E4

     GroupenCol.Add nxA_2E4
     GroupenCol.Add nxA_3e3
     GroupenCol.Add nxA_3e4
     GroupenCol.Add nxA_4e4

        LastRow = Sheets("BLS").Cells.SpecialCells(xlCellTypeLastCell).Row

          For i = 2 To LastRow
            LastCol = Sheets("BLS").Cells(i, Columns.count).End(xlToLeft).Column
            For j = 2 To LastCol
                class = Sheets("BLS").Cells(i, j).Value
                GroupAanwezig = WorksheetFunction.CountIf(Range("B1:D18"), class)
                BLSers = Sheets("BLS").Cells(i, 1).Value

            If InStr(nshow, class) = 0 Then
            GroupID(t) = class
            nshow = nshow & " " & GroupAanwezig & " " & t & " " & GroupID(t) & vbCrLf
            t = t + 1
            End If

            countCol = Sheets("BLS").Cells(i, Columns.count).End(xlToLeft).Column
            lastcolumn = countCol - 1


            Select Case lastcolumn
                Case Is = 0
                    'MsgBox "EMPTY"
                Case Is = 1
                    totally = lastcolumn * 30

                Case Is = 2
                    totally = ((lastcolumn * 10) - 5) * 2

                Case Is = 3
                    totally = lastcolumn * 10

                    nclass = "n" + class
                     MsgBox nclass
                     '---------------------------------------------------------
                     'there has to be a faster way to do the if-statement below.
                     '---------------------------------------------------------
                     If class = "xA_9N4" Then
                        MsgBox nxA_9N4
                     End If
                     If class = "xA_4A4" Then
                        MsgBox nxA_4A4
                     End If
                     If class = "xA_3A4" Then
                        MsgBox nxA_3A4
                     End If
                     If class = "xA_1B4B" Then
                        MsgBox nxA_1B4B
                     End If
                     If class = "xA_1A2B" Then
                        MsgBox nxA_1A2B
                     End If
                     If class = "xA_2A4" Then
                        MsgBox nxA_2A4
                     End If
                     If class = "xA_2E4" Then
                        MsgBox nxA_2E4
                     End If
                     If class = "xA_1E3" Then
                        MsgBox nxA_1E3
                     End If
                     '--------------------------------------------------------
            End Select
    End Sub
.

在最后一个情况下(案例是= 3)有一个 if-stalal 。这个如果语句是一个shor版本(如果在0,案例1和案例2中需要重复这一点)。我需要用返回的值(例如)nxa_9n4 做点什么。在早些时候尝试解决问题时,我得到了帮助:

工程师们他告诉我使用集合。

我使用了一个集合,但仍然:(。


评论答案: - 如果一个单元格.Value与类(始终如下)具有相同的值,则我将从另一张纸张返回值。此值计数名为“xa4a”的组/类,并将outvalue返回为nxa4a。使用ifstatement,我想知道类=“x4a”,请给我nxa4a的计数。

通过方式,eval函数在2013年不起作用。

有帮助吗?
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top