Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Say I have an array (80,10)

    In the third 'column' in dimension two (1,3 - 2,3 etc). I'm comparing the values to another array.

    Are there similar to Excels 'counta' function a way to count number of occurences of a specific value in that particular element or do I have to loop the entire array. (eg. looking for the number of times the figure '100' occures in the column).
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could store the array in a range on a worksheet (which could be hidden) and use Excel worksheetfunctions to perform the count.

    If you want to avoid that, you'd have to loop through the array.

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Denmark
    Posts
    347
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's what I am trying to achieve:

    1. Got a large range with variable number of rows and occasionally changing number of columns
    2. Filling it into a two-dimensional 'MasterArray' (xRows, yCols)
    3. Looping through the 'MasterArray' identifying a subset of records - when found added to an Array 'Tmp1' (yCols_T1, xRows_T1) (Here i now know the # of columns - # rows are still unknown, thus array must be transposed to have Redim Preserve)
    4. Temp Array is 're-transposed' to a final sub-set 'Subset1(xRows_T1, yCols_T1)'

    This snippet actually does the trick, but I'm wondering if it can't be done in a more efficient way...?

    'Loop Sales force
    For c = LBound(arrSlsInfo, 1) To UBound(arrSlsInfo, 1)
    j = 1
    'Loop array of companies found for each Sales Person
    For i = LBound(arrExtrMarketAll) To UBound(arrExtrMarketAll)
    'If company is covered by sales rep considered - build transposed arrTemp
    If arrSlsInfo(c, 3) = arrExtrMarketAll(i, 9) Then
    ReDim Preserve arrTemp(UBound(arrExtrMarketAll, 2), j)
    For f = 1 To UBound(arrExtrMarketAll, 2)
    arrTemp(f, j) = arrExtrMarketAll(i, f)
    Next f
    j = j + 1
    End If
    Next i

    'Re-transpose arrTemp - to get "correctly" oriented subset
    ReDim arrCosCovered(LBound(arrTemp, 2) To UBound(arrTemp, 2), LBound(arrTemp, 1) To UBound(arrTemp, 1))
    For d = LBound(arrTemp, 2) To UBound(arrTemp, 2)
    For e = LBound(arrTemp, 1) To UBound(arrTemp, 1)
    arrCosCovered(d, e) = arrTemp(e, d)
    Next e
    Next d
    Next c


    Question:
    Do I need to loop the temporary array to fill 'Subset1' or are there other more efficient ways of achieving the above ??
    What is the easiest way of doing this kind of extraction from an array into a subarray and is it somehow possible to do this without having to put the values into a worksheet as an intermediary step?


    ...from here I can move on filling in my worksheet etc. as required.
    Bests,
    RD


    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    It sounds to me as though you should be using worksheets and filters, or a database!
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •