在代码中给出数组值

时间:2013-07-30 18:49:35

标签: excel vba excel-vba

我创建了一个数组并给出了1到12个值的tems。我这样做后来循环遍历每个名​​称的代码的一部分。由于某种原因,我在我的第一个数组填充线上出现错误:“需要对象”。有任何想法吗?并且其他代码也有意义吗?

                Dim sArray() As String
                Dim row As Long
                Dim i As Long
                Dim arrTot() As Long
                Dim arrLate() As Long

          'Error here
                Set sArray(1) = "AAA CANADA INC."
                Set sArray(2) = "AEROTEK ULC"
                Set sArray(3) = "AKKA GROUPE AMERIQUE DU NORD INC."
                Set sArray(4) = "ALTITUDE AEROSPACE INC."
                Set sArray(5) = "ASSYSTEM CANADA"
                Set sArray(6) = "BERLETEX AERO DESIGN"
                Set sArray(7) = "MSB DESIGN INC."
                Set sArray(8) = "NORAMTEC CONSULTANTS INC."
                Set sArray(9) = "SATYAM COMPUTER SERVICES LTD."
                Set sArray(10) = "T.E.S. CONTRACT SERVICES INC."
                Set sArray(11) = "TATA CONSULTANCY SERVICES CANADA IN"
                Set sArray(12) = "TDM TECHNICAL SERVICES"

                Set vendor = Range("P2:P" & lr)
                row = 1
                For Each cell In invoicedates
                    For i = 1 To 12
                        If tbl1(row, 16) = sArray(i) Then
                            arrTot(i) = arrTot(i) + 1
                            duedate = cell.Value + 60
                            If Date > duedate Then
                                arrLate(i) = arrLate(i) + 1
                            End If
                        End If
                    Next
                    row = row + 1
                Next

1 个答案:

答案 0 :(得分:1)

两件事:首先你需要重新编辑阵列:

ReDim sArray(1 To 12)

此外,在将值分配给数组之前没有“设置”。