Array Help

G

gti_jobert

Hi all,

I have created a 2-d array that stored info;


Code
-------------------

j = i
Do
Cells(j, 3).Select
If ActiveCell.Value <> "" Then

maxArray = maxArray + 1
ReDim Preserve Arry(1 To 4, 1 To maxArray)

Arry(1, maxArray) = ActiveCell.Value
Arry(2, maxArray) = ActiveCell.Offset(0, 1).Value
Arry(3, maxArray) = Right(ActiveCell.Offset(0, 2).Value, 6)
Arry(4, maxArray) = Val(ActiveCell.Offset(0, 8).Value / 1000)

End If

-------------------


My question to you is.....if Arry(1, maxArray) and Arry(2, maxArray
and Arry(3, maxArray) are the same then I want to group them and tota
the Arry(4, maxArray) value.

Would the array first have to be sorted first and then grouped? An
advice welcome!

TI
 
T

Tom Ogilvy

Do you mean get a running total:

tot = 0
j = i
Do
Cells(j, 3).Select
If ActiveCell.Value <> "" Then

maxArray = maxArray + 1
ReDim Preserve Arry(1 To 4, 1 To maxArray)

Arry(1, maxArray) = ActiveCell.Value
Arry(2, maxArray) = ActiveCell.Offset(0, 1).Value
Arry(3, maxArray) = Right(ActiveCell.Offset(0, 2).Value, 6)
Arry(4, maxArray) = Val(ActiveCell.Offset(0, 8).Value / 1000)
if arry(1,maxArray) = arry(2,maxArray) and _
arry(2,maxArray) = arry(3,maxArray) then
tot = tot + arry(4,maxArray)
end if
End If
 
G

gti_jobert

Hi,

no I dont mean a running total, for example, if the following data wa
stored in the array;

WB01 12345 987 6
WB01 12345 987 90
WB02 84638 247 9

I want to be able to group them to produce the following;

WB01 12345 987 96
WB02 84638 247 9

with the last entry totaled if there are duplicates.

Thanks again
 
G

gti_jobert

I'm just trying to sort the Array first, does anyone know how to sort
2-d array. Examples on the web are 1-d :
 
T

Tom Ogilvy

You don't just want a method to sort a 2-D array (which I have posted in the
past), you also need a method to sort a 2-D array on multiple Keys. An
alternative would be 2-D on a single key but using a method which does a
stable/static sort. You could then sort lowest to most significance
successively - much like you can do with Excel's sort method. Unfortunately,
my method was quicksort which isn't stable/static. It might be easier to
drop your array in a worksheet and use the subtotal function under the data
menu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top