Home |
Search |
Today's Posts |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, there seems to be some continuing confusion in your thinking; or
at least in your presentation of "the problem". IsArray(iVar) will return True if iVar is a multi-celled range or an array, whether the array was declared as a true Variant() array (or an array of any other built-in type) or is an array contained within a Variant variable (whether the array so contained is of type Variant(), Integer(), String(), or whatever). So once IsArray has returned True and a range has been ruled out, the only way for iVar to be a single value is if it is an array (whether or not contained within a Variant variable) containing a single element--if it were otherwise a single value, i.e., simply a single value rather than an array containing a single element, IsArray would have returned False. So if you are trying to rule out a single element array (though it's not clear why--looping from LBound(arr,n) to UBound(arr,n) in each dimension will deal with both a single element array or a multi-element array), you can check for that directly. If the functions in the freely downloadable file at http://home.pacbell.net/beban are available to your workbook, you can check for it with ArrayCount(iVar), which will return the number of elements in the array. If those functions are not so available then the ArrayCount function is included below. As an aside, there are a couple of ways to determine whether an array was declared as true array or as an array contained within a Variant variable, but it is not clear to me why that should ever be necessary or desirable. 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] Dim j As Long, k As Long 'Convert range to array 'InputArray = InputArray If IsArray(InputArray) Then If Not TypeOf InputArray Is Range Then j = 1: k = 1 On Error Resume Next Do k = k * (UBound(InputArray, j) - _ LBound(InputArray, j) + 1) j = j + 1 Loop While Err.Number = 0 ArrayCount = k Else If TypeOf Application.Caller Is Range Then ArrayCount = "#ERROR! This function accepts only arrays." Else MsgBox "#ERROR! The ArrayCount function accepts only arrays.", 16 End If End If Else If TypeOf Application.Caller Is Range Then ArrayCount = "#ERROR! This function accepts only arrays." Else MsgBox "#ERROR! The ArrayCount function accepts only arrays.", 16 End If End If End Function Alan Beban Smallweed wrote: Hi - back again after other projects took a chunk out of my time! Thanks everyone for their contributions to this lively thread. As Alan points out, the problem area is in distinguishing between a variant variable and a variant array - I want my UDF to be flexible enough to accept either which means, once I've ruled out the input being a range, I need to know whether I just have a single value or an array to loop through. I guess I'll just have to use some error trapping on my existing code. Curious there isn't some simpler way to spot this! |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to fix an array or range | Excel Discussion (Misc queries) | |||
Range to Array | Excel Programming | |||
copy one array formula to an array range | Excel Programming | |||
Tricky array formula issue - Using array formula on one cell, then autofilling down a range | Excel Programming | |||
Array <--- Range | Excel Programming |