+ Reply to Thread
Results 1 to 5 of 5

Show last 3 chances

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2008
    Location
    Milan, Italy
    Posts
    13

    Show last 3 chances

    Hy to everybody,
    I please you need help on this problem: i have 6 items that, random, get value 1 and i want to know, on every row, the last 3 divers items that has the 1 value. Hope to be clear i attach an example. Thanks in advance.
    Regards
    Davide
    Attached Files Attached Files

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Show last 3 chances

    Given the need for each value to also be unique I think a native function will prove expensive (& ugly) ... are you open to a UDF ? (ie VBA Custom Function)

  3. #3
    Registered User
    Join Date
    04-04-2008
    Location
    Milan, Italy
    Posts
    13

    Re: Show last 3 chances

    Quote Originally Posted by DonkeyOte View Post
    Given the need for each value to also be unique I think a native function will prove expensive (& ugly) ... are you open to a UDF ? (ie VBA Custom Function)
    Yes, i think will be no problem with VBA function...
    Regards
    Davide

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Show last 3 chances

    Not very elegant but perhaps along the lines of:

    Function Last3Unique(rngHdrs As Range, rngVals As Range, rngPrec As Range) As Variant
    Dim vResults(), lngRow As Long, lngCol As Long
    vResults = Evaluate("IF(ROW(" & rngVals.Address & "),REPT(" & rngHdrs.Address & "," & rngVals.Address & "))")
    For lngRow = UBound(vResults, 1) To 1 Step -1
        For lngCol = UBound(vResults, 2) To 1 Step -1
            If vResults(lngRow,lngCol) <> "" And Application.CountIf(rngPrec, vResults(lngRow, lngCol)) = 0 Then
                Last3Unique = vResults(lngRow, lngCol)
                If IsNumeric(Last3Unique) Then Last3Unique = Val(Last3Unique)
                Exit Function
            End If
        Next lngCol
    Next lngRow
    End Function
    Above stored in a Standard Module and called from cells per

    K5: =LAST3UNIQUE($A$1:$F$1,$A$2:$F5,$J5:J5)
    copied down and across - eg I was using replica matrix K5:M33

    Whre first parameter specifies headers, second values to be used up to that point, third specifies preceding results

    NOTE: the above requires you have a blank column to left of first result column - ie J is blank
    (this is to validate that current result is unique for the row)
    You should find that you can alter the headers etc and the UDF would reflect immediately.
    Last edited by DonkeyOte; 10-06-2009 at 12:30 PM.

  5. #5
    Registered User
    Join Date
    04-04-2008
    Location
    Milan, Italy
    Posts
    13

    Re: Show last 3 chances

    Great DonkeyOte! It works!
    Thank you very much
    Davide

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1