Re: Filter an array by Doug
Doug
Sun Sep 10 13:36:23 CDT 2006
Something like this:
Dim myarray As Variant
Dim newarray As Variant
ReDim myarray(4, 2)
Dim i As Long, j As Long, k As Long
For i = 0 To 2
myarray(i, 0) = "A"
For j = 1 To 2
myarray(i, j) = "Item" & Format(i) & Format(j)
Next j
Next i
For i = 3 To 4
myarray(i, 0) = "B"
For j = 1 To 2
myarray(i, j) = "Item" & Format(i) & Format(j)
Next j
Next i
k = 0
For i = 0 To 4
If myarray(i, 0) = "B" Then
k = k + 1
End If
Next i
ReDim newarray(k - 1, 2)
k = 0
For i = 0 To 4
If myarray(i, 0) = "B" Then
For j = 0 To 2
newarray(k, j) = myarray(i, j)
Next j
k = k + 1
End If
Next i
For i = 0 To 4
For j = 0 To 2
MsgBox "myarray - " & myarray(i, j)
Next j
Next i
For i = 0 To k - 1
For j = 0 To 2
MsgBox "newarray - " & newarray(i, j)
Next j
Next i
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Hege M" <HegeM@discussions.microsoft.com> wrote in message
news:39A64C34-0E17-4E1B-BCB2-44ED3800892F@microsoft.com...
> Hey!
>
> I have a multidimensional array and I wan't to filter this array into an
> other variable.
> The array is something like A(Projectnr, SampleNr, Info) and I would like
> to
> be able to show just those records that have projectnr = B.
>
> Is there an easy way to do this?
>
> Hope someone can help me.
> Thanks.
>
> Hege