User Tools

Site Tools


microsoft_excel:macros:search_sequentially

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

microsoft_excel:macros:search_sequentially [2021/08/04 14:25] – created petermicrosoft_excel:macros:search_sequentially [2021/08/04 14:43] (current) – removed peter
Line 1: Line 1:
-====== Microsoft Excel - Macros - 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, 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 
-</code> 
- 
-and 
- 
-<code excel> 
-' Tries to find vCrit within oArrWithCrit. 
-' If found then returns vFoundValue otherwise vNotFoundValue. 
-'=ArrayFind(A1:A1000,"Foo",B1:B1000) 
-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, 1) To UBound(oArrWithCrit, 1) 
-        If oArrWithCrit(lRow, 1) = vCrit Then 
-            ArrayFindSequentialEx = vFoundValue 
-            Exit Function 
-        End If 
-    Next 
- 
-     
-    ' Clear all objects. 
-    Set vArr1 = Nothing 
-    Set vArr2 = Nothing 
- 
-End Function 
-</code> 
  
microsoft_excel/macros/search_sequentially.1628087118.txt.gz · Last modified: 2021/08/04 14:25 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki