microsoft_excel:macro_count_binary
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
microsoft_excel:macro_count_binary [2016/07/11 11:20] – created peter | microsoft_excel:macro_count_binary [2021/08/04 14:06] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Microsoft Excel - Macro Count Binary ====== | ||
- | |||
- | <code excel> | ||
- | ' Binary Count of array. | ||
- | ' Returns the number of vCrit found within the array oArrWithCrit. | ||
- | Function ArrayCountIf(oArrWithCrit As Variant, vCrit As Variant) | ||
- | Dim low As Long | ||
- | low = LBound(oArrWithCrit) | ||
- | Dim high As Long | ||
- | high = UBound(oArrWithCrit) | ||
- | Dim i As Long | ||
- | Dim J As Long | ||
- | Dim result As Boolean | ||
- | | ||
- | ArrayCountIf = 0 | ||
- | | ||
- | Do While low <= high | ||
- | i = (low + high) / 2 | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | ' Now that found run sequentially while same value | ||
- | J = i - 1 | ||
- | i = i + 1 | ||
- | | ||
- | Do While (i <= high) | ||
- | If vCrit = oArrWithCrit(i, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | i = i + 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Do While (J >= low) | ||
- | If vCrit = oArrWithCrit(J, | ||
- | ArrayCountIf = ArrayCountIf + 1 | ||
- | J = J - 1 | ||
- | Else | ||
- | Exit Do | ||
- | End If | ||
- | Loop | ||
- | | ||
- | Exit Do | ||
- | ElseIf vCrit < oArrWithCrit(i, | ||
- | high = (i - 1) | ||
- | Else | ||
- | low = (i + 1) | ||
- | End If | ||
- | Loop | ||
- | | ||
- | End Function | ||
- | </ | ||
microsoft_excel/macro_count_binary.1468236040.txt.gz · Last modified: 2020/07/15 09:30 (external edit)