User Tools

Site Tools


excel:macro_search_sequentially

This is an old revision of the document!


Excel - Macro Search Sequentially

' Tries to find vCrit within oArrWithCrit.
' If found then return corresponding oArrWithValues otherwise vDefault.
Function ArrayFindSequential(oArrWithCrit As Variant, vCrit As Variant, oArrWithValues As Variant, vDefault As Variant)
 
    Dim vArr1 As Variant
    Dim vArr2 As Variant
    Dim lRow As Long
    ArrayFindSequential = vDefault
    If (UBound(oArrWithCrit) - LBound(oArrWithCrit)) = (UBound(oArrWithValues) - LBound(oArrWithValues)) Then
        For lRow = LBound(oArrWithCrit, 1) To UBound(oArrWithCrit, 1)
            If oArrWithCrit(lRow, 1) = vCrit Then
                ArrayFindSequential = oArrWithValues(lRow, 1)
                Exit Function
            End If
        Next
    Else
        ArrayFindSequential = "Criteriarange and sum range must be of same length"
    End If
 
 
    ' Clear all objects.
    Set vArr1 = Nothing
    Set vArr2 = Nothing
 
End Function
excel/macro_search_sequentially.1468225734.txt.gz ยท Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki