You are on page 1of 9

'Copyright 2000 Alan Beban 35

Function ArrayCount(InputArray)
'This function counts NOT the number of
'non-blank values in the array, but the
'number of available slots for values,
'whether the slots contain anything or not.
'It's similar to the Count Property (e.g.,
'Range("a1:c3").Count).

Function RowVector(InputArray, RowNumber)


'This function returns an individual row
'vector from a one- or two-dimensional array

Function ColumnVector(InputArray, ColumnNumber)


'This function returns an individual column
'vector from a one- or two-dimensional array

Function SubArray(inputArray, Optional ByVal NewFirstColumn, Optional ByVal NewLastColumn, _


Optional ByVal NewFirstRow, Optional ByVal NewLastRow)
'This function returns as an array any sub array of
'a one- or two-dimensional input array/range, as defined by
'the new first and last rows and columns.

Function SubArray3D(inputArray, Optional ByVal NewFirstRow, _


Optional ByVal NewLastRow, Optional ByVal NewFirstColumn, _
Optional ByVal NewLastColumn, Optional ByVal NewFirst3rd, _
Optional ByVal NewLast3rd)
'This function returns as an array any sub array of
'a three-dimensional input array, as defined by
'the new first and last rows, columns and 3rd dimension.

Function ArrayCountIf(InputArray, SoughtValue, Optional Op, _


Optional MatchCase As Boolean = False, Optional dDate)
'This function counts the occurrences of a particular
'value or values, or instances of comparisons in an
'array (or range). To count empty strings the call is
'ArrayCountIf(myArray,""). To count empty blanks it is
'ArrayCountIf(myArray,"="). To count = signs it is
'ArrayCountIf(myArray,"=","="). The Function is case-
'sensitive if True is entered as the fourth (optional)
'argument; if it is case-sensitive, the comparisons
'are in accordance with Option Compare Binary; if not,
'then in accordance with Option Compare Text.

Function ArrayRank(varValue, varArray, Optional varOrder = 0)


'This function is designed to operate on arrays as the
'worksheet RANK function operates on ranges.

Function ArrayTranspose(InputArray)
'This function returns the transpose of
'the input array or range; it is designed
'to avoid the limitation on the number of
'array elements that the worksheet TRANSPOSE
'Function has.

Function ArrayRowFilter1(InputArray, FilterColumn As Integer, _


FilterValue, Optional Op, Optional MatchCase As Boolean = False)
'This function returns an array of the elements in rows of an
'array in which the value in the specified Filter Column
'compares, as specified in the fourth argument, to the specified
'Filter Value; if the fourth argument is omitted, the comparison
'is equality. The filtering is case sensitive unless the fifth
'argument is entered as False. If the Function is called as
'case sensitive, the comparison is determined by Option Compare
'Binary; if not case sensitive, by Option Compare Text.

Function ArrayRowFilter2(InputArray, FilterColumn As Integer, _


FilterValue, Optional Op, Optional MatchCase As Boolean = False)
'This function is virtually identical to ArrayRowFilter1. It is
'provided to facilitate selecting the appropriate number of cells
'when calling multiple filters from the worksheet; the syntax
'is ArrayRowFilter2(ArrayRowFilter1(ArrayRowFilter1...)...)...)

Function ArrayColumnFilter(InputArray, FilterRow, FilterValue)


'This function for filtering columns is
'analogous to the original, unrevised ArrayRowFilter

Function VLookups(lookupValue, lookupArray, ColumnNumber)


'This function acts somewhat like the built-in VLookup
'Function with exact matches, except that it returns an
'array of all the values corresponding to multiple
'occurrences of the sought value in the left hand column
'(i.e., the first column vector in the lookup array).

Function HLookups(lookupValue, lookupArray, RowNumber)


'This function is the analog of the VLookups Function
'documented above.

Function VLookupLeft(lookupValue, lookupArray As Range, _


returnValueColumn As Integer, _
Optional lookupValueColumn As Integer = -257)
'This function performs a simple lookup for values
'to the left (as well as to the right) of the
'lefthand column of the lookup array. And with 4th
'argument added, it allows any column of the
'lookupArray to be used rather than the lefthand
'column.

Function ArrayMatch(lookupValue, lookupArray, _


Optional Output = False, Optional RefStyle = 1, _
Optional CaseMatching As Boolean = False)
'Without an optional argument, this procedure outputs a
'two-column array that contains in each row the row index
'and column index of an occurrence of the lookup value
'in the lookup array (which, if it is a range, must be
'a single area); the entire array is the set of the
'row and column indices of all the occurrences of the
'lookup value. If "A" is entered as the first
'optional argument, and if the input lookup array is
'a worksheet range, the procedure outputs a one-column
'array of the cell addresses of all occurrences of the
'lookup value. The reference style of the addresses is
'determined by the optional fourth argument; absolute
'row and column references is the default, and an
'argument of 2, 3 or 4 assigns the same reference style
'as those arguments for the worksheet ADDRESS function.
'*IF THE LOOKUP VALUE DOES NOT OCCUR IN THE LOOKUP ARRAY*,
'and the function is not being called from the worksheet,
'then the function will return an unannounced error, so
'the calling code should provide for that. E.g., if the
'calling code is in a Sub procedure as x=ArrayMatch([whatever]),
'the call could be followed by If IsError(x) Then [do whatever
'should be done if no matches are found].

Function ArrayMatch3D(lookupValue3, lookupArray3, _


Optional CaseMatching3 As Boolean = False)
'This procedure outputs a three-column array that
'contains in each row the row index, column index
'and 3rd dimension index of an occurrence of the
'lookup value in the lookup array; the entire
'array is the set of the row, column and 3rd
'dimension indices of all the occurrences of the
'lookup value. *IF THE LOOKUP VALUE DOES NOT OCCUR
'IN THE LOOKUP ARRAY*, then the function will
'return an unannounced error, so the calling code
'should provide for that. E.g., if the calling code
'is in a Sub procedure as x=ArrayMatch3D([whatever]),
'the call could be followed by If IsError(x) Then
'[do whatever should be done if no matches are found].
'The methodology of the function is, conceptualizing
'the input 3-D array as a cube, to extract 2-D planes,
'find matches within each plane with the ArrayMatch
'function (which operates on 2-D arrays), add the
'number of the third dimension to the array of plane
'matches, and add that set of indices to the output array.

Function ReplaceElement(inputArray, FromValue, ToValue)


'This procedure replaces all occurrences of a specified value
'(i.e., "FromValue") in an array with a different
'specified value (i.e., "ToValue").
Function ReplaceRow(ByRef a As Variant, ByVal b As Variant, _
RowIndex As Long)
'This function replaces with _b_ the row of array _a_
'indicated by RowIndex. Currently _a_ must be a 2-D
'nonhierarchical array; _b_ can be (almost) anything with
'its number of elements equal to the row size of _a_. If
'successful, returns True and _a_ is modified as a side-effect;
'otherwise, returns False and _a_ is left unmodified.

Function ReplaceColumn(ByRef a As Variant, _


ByVal b As Variant, _
ColumnIndex As Long)
'This function replaces with _b_ the column of array _a_
'indicated by ColumnIndex. Currently _a_ must be a 2-D
'nonhierarchical array; _b_ can be (almost) anything with
'its number of elements equal to the column size of _a_.
'If successful, returns True and _a_ is modified as a side-

Function ReplaceCorner( _
ByRef a As Variant, _
ByVal b As Variant) As Boolean
'This function replaces the section of _a_ with _b_ so that the
'bottom-right entry of b is the bottom-right entry of _a_.
'Currently _a_ must be a 2-D nonhierarchical array; _b_ can be
'anything no larger than _a_.
'If successful, returns True and _a_ is modified as a side-efect;
'otherwise, returns False and _a_ is left unmodified. Based
'substantially on a function written by Harlan Grove.

Function Replace3DPlane(inputArray, Replacement, _


iNum As Integer, Optional Orientation = "xy")
'This function replaces any plane of a 3-D array.
'It returns True if the replacement is successful,
'False if it is not.

Function ReplaceSubArray( _
ByRef a As Variant, _
ByVal b As Variant, iRow As Variant, iCol As Variant) As Boolean
'This function replaces a section of array _a_, commencing with
'the element at a(iRow, iCol), with the elements of _b_.
'Currently _a_ must be a 2-D nonhierarchical array; _b_ can be
'(almost) anything no larger than the portion of a to the right
'and down from a(iRow, iCol). If successful, returns True and
' _a_ is modified as a side-efect; otherwise, returns False and
' _a_ is left unmodified. Inspired by a ReplaceCorner function
'written by Harlan Grove.

Function ArrayDimensions(InputArray)
'This function returns the number of dimensions
'of the input array
Function ConvertBase(InputArray, ResultingBase)
'This function converts an input array to
'a 0-based array or a 1-based array, in
'accordance with the ResultingBase argument
'(either 0 or 1). It accepts arrays with a
'base equal to the number of the ResultingBase
'argument, simply leaving them as is.

Function Assign(InputRange As Variant, _


inputArray As Variant) As Boolean
'The direct assignment of a range to an array a la
'myArray = Range("A1:C3") works only for Variant arrays.
'This function allows the direct transfer, in form, to
'any built-in type of array a la
'Assign Range("A1:D3"), myArray.
'The function returns True if the assignment
'succeeds, False if it fails. If InputRange is a range
'of more than one Area, the output will be to a one-
'dimensional array (which can be reshaped with the
'ArrayReshape function).

Function MakeArray(ParamArray InputParameter()) As Variant


' This function will accept virtually any type of basic
' input, and return a one-dimensional "horizontal" array
' (0-based or 1-based in accordance with the last input
' argument), including all the elements of the input data.
' The function will accept arrays of arrays to two levels.
' It is called with, e.g., for a 0-based output array:
' arr = MakeArray(array1, range1, string1, arrayOfArrays, _
' range2, value2, 0)

Function MatchingValues(indexArray, matchArray, matchValue)


'This function returns an array of the values in an
'array (indexArray) that match a specified value
'(matchValue) in another equal sized array (matchArray).

Function ArrayReshape(InputArray, NumberRows, NumberColumns, _


Optional ByColumns As Integer = -1)
'This function returns a rectangular, NumberRows X NumberColumns,
'array containing the elements of the input array or range.
'Without the optional argument it fills the output array
'row by row; with the optional argument (i.e., 1), it fills
'the output array column by column

Function ArrayUniques(inputArray, _
Optional MatchCase As Boolean = True, _
Optional Base_Orient As String = "1vert", _
Optional OmitBlanks As Boolean = True)
'THIS PROCEDURE REQUIRES A PROJECT REFERENCE
'TO "MICROSOFT SCRIPTING RUNTIME".
'The function returns an array of unique
'values from an array or range. By default
'it returns a 1-based vertical array; for
'other results enter "0horiz", "1horiz" (for
'0-based or 1-based 1-D output) or
'"0vert" for 0-based vertical output) as the
'third argument. By default, the function is
'case-sensitive; i.e., e.g., "red" and "Red"
'are treated as two separate unique values;
'to avoid case-sensitivity, enter False as
'the second argument.

Function RowsEqual(Row1, Row2)


'This function checks to see if two "rows"
'of an array or range are equal; it returns
'True if they are, False if they are not.

Function ColumnsEqual(Column1, Column2)


'This function for comparing columns
'is analogous to the RowsEquals function.

Function ScalarMult(InputArray, ScalarMultiplier As Single)


'This function returns the array resulting from
'multiplying each element of the input array by
'the scalar multiplier

Function ArrayAdd(Array1, Array2, Optional Add = True)


'This function returns an array in which the
'elements of the second input array have been
'added to or subtracted from those of the first
'input array. To add, omit the optional argument
'or insert "Add" (without the quotes) as the optional
'argument; to subtract, insert "subtract" (without
'the quotes) as the optional argument.

Function ArrayAlternates(InputArray, _
'Optional Odds As Boolean = True,
'Optional RowOrientation As Boolean = True)
'This function returns every odd or even row or
'column, depending on the input arguments. For every
'odd row, the second argument is True (or omitted);
'for every even row, the second argument is False;
'for every odd column, the second argument is True
'(or omitted) and the third is False; for every even column,
'the second argument is False and the third is False.

Sub ResizeArray(ByRef myArray As Variant, _


ParamArray tempDim() As Variant)
'ReDim Preserve can be used to change the size of
'only the last dimension of an array while
'preserving its values; this Sub procedure, while
'preserving the values of the array that is passed
'to it, will change the size of any or all of the
'dimensions of a one-, two- three- or four-dimensional
'array, or increase or decrease the number
'of the array's dimensions. Its arguments are the
'array and, optionally, its new dimensions.

Function OneD(inputArray)
'This function changes a 2-D single row array to 1-D
'without the limitations of the built-in TRANSPOSE
'and INDEX functions; i.e., without the limit on array
'elements and without changing the type of the array

Function TwoD(inputArray, Optional Orientation As _


String = "xy", Optional planeOffset As Integer = 0)
'This function changes a 1-D or 3-D array to a
'2-D array (or leaves a 2-D array as is). If the
'input array is a 3-D array, the 2-D result can be
'coincident with or parallel to the first two
'dimensions (visualize the xy-plane), coincident with
'or parallel to the 1st and 3rd (visualize the xz-plane),
'or coincident with or parallel to the 2nd and 3rd (vis-
'ualize the yz-plane); By default it is coincident
'with the xy-plane.

Function ThreeD(inputArray)
'This function changes a 1-D or 2-D array to
'a 3-D array (or leaves a 3-D array as is).

Function FourD(inputArray)
'This function changes a 1-D or 2-D or 3-D array
'(or a range) to a 4-D array (or leaves a
'4-D array as is).

Function AddXYPlane(arr3D, arr2D)


'This function adds to a 3-D array (of rows,
'columns and levels) an additiional plane(i.e.,
'an additional array of rows and columns)

Function Delete3DPlane(inputArray, Optional _


planeOffset As Integer = 0, _
Optional Orientation = "xy")
'This function deletes a plane from a 3-D
'array. The deleted plane can be coincident
'with or parallel to the first two dimensions
'(visualize the xy-plane), coincident with or
'parallel to the 1st and 3rd (visualize the
'xz-plane), or coincident with or parallel to
'the 2nd and 3rd (visualize the yz-plane); by
'default it is coincident with the xy-plane.

Function Load3D(ParamArray iAreas())


'This function builds a 3-D array from
'2-D arrays and/or ranges

Sub Deposit3DArray(inputArray)
'This procedure puts the values from
'a 3-D array onto a worksheet. Visualizing
'the 3-D array as a rectangular solid
'sitting on the xy-plane (analogous to the
'rows and columns plane of a worksheet),
'beginning at Cell B2 are deposited the
'contents of the two-D arrays in the xy-plane
'and the parallel planes at each level of the
'third dimension.

Sub Reload3DFromWorksheet(Optional Orientation As String = "XY")


'This procedure assumes that the elements of a 3-D array
'were previously deposited into a worksheet(s) named "XY" and/or
'"XZ" and/or "YZ" by means of the Deposit3DArray procedure. It
'also assumes that the workbook into which those elements were
'previously deposited is the active workbook. The procedure
'reloads the 3-D array with those elements.

Sub Save3DInNames(inputArray, arrayName)


'This procedure stores the values from
'a 3-D array into workbook names. Visualizing
'the 3-D array as a rectangular solid
'sitting on the xy-plane (analogous to the
'rows and columns plane of a worksheet),
'the contents of the two-D arrays in the xy-plane
'and the planes parallel to it at each level of the
'third dimension are stored in workbook names
'from where they can be retrieved after the procedure
'has ended. E.g., if the array name were "myArray", the
'planes would be stored in myArrayPlaneXY0,
'myArrayPlaneXY1, etc., where the number at the end
'of the name refers to the offset of the respective plane
'from the xy-plane.

Function Load3DFromNames(Base As Boolean, _


arrayName As String, firstPlane)
'This function loads a 3-D array from where
'it was stored in workbook names. It is called like
'w = Load3DFromNames(0, "myArray", [myArrayPlaneXY0])

Function DeleteColumn(inputArray, ColumnNumber)


'This function returns the input array minus
the column(s) specified by ColumnNumber.

Function DeleteRow(inputArray, RowNumber)


'This function returns the input array minus
'the row(s) specified by RowNumber.

You might also like