仅1个数据时输出异常

时间:2019-05-01 00:58:50

标签: excel vba

当执行代码时,我有以下代码来显示输出。 一切正常,除了只有一个数据可用时显示的输出。

Sub STELStatusCheck_click()
Dim MyArray()
Dim LastRow As Long, LastRow2 As Long
Dim ctr As Long
Dim ws As Worksheet
Application.ScreenUpdating = False
On Error Resume Next

LastRow = Sheet11.Cells(Sheet11.Rows.Count, 2).End(xlUp).Row
LastRow2 = Sheet13.Cells(Sheet13.Rows.Count, 2).End(xlUp).Row

With Sheet11
    ctr = 0
    For i = 4 To LastRow

        If .Cells(i, 18) = "Closed" Then
            If IsError(Application.Match(.Cells(i, 5).Value,  Sheet13.Columns(5), 0)) Then
                ReDim Preserve MyArray(0 To 2, 0 To ctr)
                MyArray(0, ctr) = .Cells(i, 5).Value
                MyArray(1, ctr) = .Cells(i, 6).Value
                MyArray(2, ctr) = "Waiting Installation"
                ctr = ctr + 1
            ElseIf Not IsError(Application.Match(.Cells(i, 5).Value, Sheet13.Columns(5), 0)) And Evaluate("Sumproduct((sktPCE!e6:e" & LastRow2 & "=""" & _
                           .Cells(i, 5) & """)*(sktPCE!u6:u" & LastRow2 & "=""In Service""))") = 0 Then
                ReDim Preserve MyArray(0 To 2, 0 To ctr)
                MyArray(0, ctr) = .Cells(i, 5).Value
                MyArray(1, ctr) = .Cells(i, 6).Value
                MyArray(2, ctr) = "Waiting Installation"
                ctr = ctr + 1
            End If
        End If
    Next i
End With
With UserForm1
    With .ListBox1
        .Clear
        .ColumnHeads = False
        .ColumnCount = 3
        .ColumnWidths = "50;50;50"
        .List = Application.WorksheetFunction.Transpose(MyArray)
        .TopIndex = 0
    End With
    .Show

    End With
    Application.ScreenUpdating = True
    End Sub

第一张图片是我所说的异常,应该将输出显示为第二张图片。

输出异常
Abnormal output

所需的输出
Desired output

0 个答案:

没有答案