-1

I created an array and gave tems 1 to 12 values. I did this to later loop through a part of code with each name. for some reason i get an error at my firs array fill line: "Object required". any ideas? And doe the rest of this code make sense too?

                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
user2385809
  • 955
  • 7
  • 15
  • 26
  • 4
    As the error suggests `Set` is used for setting references to objects, not for assigning values. Remove the `Set`s. You must also dimension your array before using or get out of range errors. – A. Webb Jul 30 '13 at 19:01
  • 1
    you delcare the array but never set its size use the redim feature to resize your array. ReDim sArray(12). Also note that unless you declare option base 1 in the module then all array index's start at 0 – Sorceri Jul 30 '13 at 19:01
  • 2
    Define array as `Dim sArray(1 To 12) As String` and remove Set while assigning values to them. – Santosh Jul 30 '13 at 19:01
  • this worked thank you. so what would set be for, like assigning a range to a range variable? is that an object? – user2385809 Jul 30 '13 at 19:14
  • 1
    http://stackoverflow.com/questions/349613/what-does-the-keyword-set-actually-do-in-vba – chancea Jul 30 '13 at 19:17
  • just fyi as you may find it convenient in the future, you can use the Array function to return a variant array based on the args, so e.g. rather than going x(1) = "a", x(2) = "b" etc, you can do x = Array("a","b") – Cor_Blimey Jul 30 '13 at 20:38

1 Answers1

1

Two things: First you need to redim your array:

ReDim sArray(1 To 12)

Also, there is no 'Set' before assigning the values to an array.

Abe Gold
  • 2,307
  • 17
  • 29