Function ArrayCountIf(arr As Variant, str As String) As Integer
Dim i As Integer, iCount As Integer
For i = LBound(arr) To UBound(arr)
If arr(i) = str Then iCount = iCount + 1
Next i
ArrayCountIf = iCount
End Function
Application.Count(Application.Match(SavedArray(), Array([lookup_value]), 0))
Sub M1ArrayCount()
Dim arrNumbers() As Variant
Dim Long1 As Long
Dim Loop1 As Long
arrNumbers() = ThisWorkbook.Sheets(1).Range("A2:A11").Value
With ThisWorkbook.Sheets(1)
For Loop1 = 1 To 6
.Cells(Loop1 + 1, 4).Value = Application.Count(Application.Match(arrNumbers(), Array(Loop1), 0))
Next Loop1
End With
End Sub
Public Function GetIndex(ByRef iaList() As Variant, ByVal value As Variant) As Long
Dim i As Long
For i = LBound(iaList) To UBound(iaList)
If value = iaList(i) Then
GetIndex = i
Exit For
End If
Next i
End Function
Public Function GetIndex(ByRef iaList() As Integer, ByVal value As Integer) As Integer
Dim i As Integer
For i = LBound(iaList) To UBound(iaList)
If iaList(i) = value Then: GetIndex = i: Exit For:
Next i
End Function
VBA Find Index in Array
Private Function WhereInArray(arr1 As Variant, vFind As Variant) As Variant
'DEVELOPER: Ryan Wells (wellsr.com)
'DESCRIPTION: Function to check where a value is in an array
Dim i As Long
For i = LBound(arr1) To UBound(arr1)
If arr1(i) = vFind Then
WhereInArray = i
Exit Function
End If
Next i
'if you get here, vFind was not in the array. Set to null
WhereInArray = Null
End Function
Check if Value is in Array using VBA
Private Function IsInArray(valToBeFound As Variant, arr As Variant) As Boolean
'DEVELOPER: Ryan Wells (wellsr.com)
'DESCRIPTION: Function to check if a value is in an array of values
'INPUT: Pass the function a value to search for and an array of values of any data type.
'OUTPUT: True if is in array, false otherwise
Dim element As Variant
On Error GoTo IsInArrayError: 'array is empty
For Each element In arr
If element = valToBeFound Then
IsInArray = True
Exit Function
End If
Next element
Exit Function
IsInArrayError:
On Error GoTo 0
IsInArray = False
End Function
The base of an array created with the Array function is zero; it is unaffected by Option Base.
Arrays for which dimensions are set by using the To clause in a Dim, Private, Public, ReDim, or Static statement can
have any integer value as a lower bound.
Option Base statement
Used at the module level to declare the default lower bound for array subscripts.
Syntax
Option Base { 0 | 1 }
Remarks
Because the default base is 0, the Option Base statement is never required. If used, the statement must
appear in a module before any procedures. Option Base can appear only once in a module and must
precede array declarations that include dimensions.
Option Base 1 ' Set default array subscripts to 1.
Dim Lower
Dim MyArray(20), TwoDArray(3, 4) ' Declare array variables.
Dim ZeroArray(0 To 5) ' Override default base subscript.
' Use LBound function to test lower bounds of arrays.
Lower = LBound(MyArray) ' Returns 1.
Lower = LBound(TwoDArray, 2) ' Returns 1.
Lower = LBound(ZeroArray) ' Returns 0.
If A > 10 Then A = A + 1 : B = B + A : C = C + B
For Each...Next statement
Repeats a group of statements for each element in an array or collection.
For Each element In group
[ statements ]
[ Exit For ]
[ statements ]
Next [ element ]
Sub Advanced_Filtering() 'FILTER THE MAIN DATABASED BETWEEN START AND END VALUES AND PRINT THE NEXT DRAW
Range("DATA").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("Criteria1") 'FILTER THE MAIN DATABASED BETWEEN START AND END VALUES
Range("DATA").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("Criteria2"), CopyToRange:=Range("NEXT_DRAW_FILTER_RESULTS") ' PRINTS NEXT DRAW FILTERS
For i = 1 To 52
Application.Run "PRED" & i
Next i
End Sub
For L = LBound(IN_SEL) To UBound(IN_SEL)
NT = IN_SEL(L)
If CountIf(SAMP, NT) > THRESHOLD Then
GI = GI + 1
ReDim Preserve S_IN_SEL(GI)
End If
Next L
dim arr(1 To 4) As Integer
arr() = Array(3, 7, 5, 2)
or
dim arr(1 to 4) As String
arr() = Array("How", "Now", "Brown", "Cow")
get specific value of a named range in excel vba
RANGE("ODD_C.")(1)
Check if Array is Initialized (If it
contains elements or not)
If Not Not myArray Then MsgBox UBound(myArray) Else MsgBox "myArray not initialised"