microsoft_excel:macro_search_sequentially
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
microsoft_excel:macro_search_sequentially [2016/07/11 11:30] – created peter | microsoft_excel:macro_search_sequentially [2021/08/04 14:25] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Search Sequentially ====== | ||
- | |||
- | <code excel> | ||
- | ' 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, | ||
- | If oArrWithCrit(lRow, | ||
- | ArrayFindSequential = oArrWithValues(lRow, | ||
- | Exit Function | ||
- | End If | ||
- | Next | ||
- | Else | ||
- | ArrayFindSequential = " | ||
- | End If | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | </ | ||
- | |||
- | and | ||
- | |||
- | <code excel> | ||
- | ' Tries to find vCrit within oArrWithCrit. | ||
- | ' If found then returns vFoundValue otherwise vNotFoundValue. | ||
- | ' | ||
- | Function ArrayFindSequentialEx(oArrWithCrit As Variant, vCrit As Variant, vFoundValue As Variant, vNotFoundValue As Variant) | ||
- | Dim vArr1 As Variant | ||
- | Dim vArr2 As Variant | ||
- | Dim lRow As Long | ||
- | ArrayFindSequentialEx = vNotFoundValue | ||
- | For lRow = LBound(oArrWithCrit, | ||
- | If oArrWithCrit(lRow, | ||
- | ArrayFindSequentialEx = vFoundValue | ||
- | Exit Function | ||
- | End If | ||
- | Next | ||
- | |||
- | | ||
- | ' Clear all objects. | ||
- | Set vArr1 = Nothing | ||
- | Set vArr2 = Nothing | ||
- | |||
- | End Function | ||
- | </ | ||
microsoft_excel/macro_search_sequentially.1468236613.txt.gz · Last modified: 2020/07/15 09:30 (external edit)