Excel VBA reminders / snipbits

By | February 21, 2014

Consider using Collections, not arrays


Use SET when assigning Objects

Selec All Code:
1
Set InvoiceWS = ActiveWorkbook.Sheets("Invoice")

Selec All Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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