LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Range or Array?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix an array or range delboy Excel Discussion (Misc queries) 1 February 12th 08 08:14 PM
Range to Array Gary''s Student Excel Programming 5 June 7th 07 09:22 PM
copy one array formula to an array range guedj54 Excel Programming 2 October 29th 06 07:38 PM
Tricky array formula issue - Using array formula on one cell, then autofilling down a range aspenbordr Excel Programming 0 July 27th 05 03:59 PM
Array <--- Range Charley Kyd[_2_] Excel Programming 7 January 14th 04 08:00 AM


All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"