View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Juan Sanchez Juan Sanchez is offline
external usenet poster
 
Posts: 19
Default Function to resize an array

Hi all...
I was trying to write a function that would help me resize
an array in such a way that when I apply the function to
it, it will eliminate the *empty spaces* of the array.

The array I'm trying to modifie is like the one that would
return a formula like =IF(A1:J1=1,A2:J2,"") for each cell
different from 1 on row 1 I would get a empty space in my
array so if I have

A B C D E F G H I J
R1 1 2 1 1 3 2 1 2 2 1
R2 3 4 2 5 7 2 6 4 5 8

my formula would result in {3, ,2,5, , ,6, , ,8}
and after applying my new function which I called
CleanArr, the result would be {3,2,5,6,8}

Here's were I'm at now:
'========================================
Function CleanArr(OrArr As Variant) As Variant
Dim i, j, k As Integer
Dim FixArr(), CPArr() As Variant

CPArr = OrArr
i = 0
For j = 1 To UBound(CPArr())
If CPArr(j) < Empty Then i = i + 1
Next j
ReDim FixArr(i - 1)
j = 1
For k = 0 To UBound(FixArr())
If CPArr(j) < Empty Then
FixArr(k) = CPArr(j)
Else
k = k - 1
End If
j = j + 1
Next k
CleanArr = FixArr
End Function
'========================================

As it is above, it works, if I use:
=CleanArr(IF(A1:J1=1,A2:J2,"")CTR+SHF+ENT, it will return
{3,2,5,6,8}

But... and here's were I'm stuck, if I use it in a column
orientation i.e. =CleanArr(IF(A1:A10=1,B1:B10,""))

It returns #VALUE!

I am LOST how can I make it work in both orientations,
it's intended for single dimension arrays but I want it to
work either in a row or a column...

Any help is greatly appreciated...

TIA
Juan