Excel VBA reminders / snipbits

By | February 21, 2014

Consider using Collections, not arrays


Use SET when assigning Objects

Set InvoiceWS = ActiveWorkbook.Sheets("Invoice")

Function InArray(arr, val) As Boolean
   For arrloop = LBound(arr) To UBound(arr)
      If arr(arrloop) = val Then
        InArray = True
        Exit Function
      End If
   Next arrloop
   InArray = False
End Function

Dim ListOfDirectors As Variant: ListOfDirectors = Array(2, 5, 6, 10, 117, 120)
  
If InArray(ListOfDirectors, 2) Then
  MsgBox ("2 is in")
End If