+ Reply to Thread
Results 1 to 5 of 5

Matrix Help

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    Matrix Help

    I have a set of 4 columns with YES/NO statements in them.
    I need to find any YES strings, of three or more, within one column, uninterupted by a YES in another colum.

    EXAMPLE:
    _____A ___B__C__D__E
    1 1/1/2008 YES NO NO NO
    2 1/2/2008 NO NO YES YES
    3 1/3/2008 YES NO NO NO
    4 1/4/2008 YES NO NO NO
    5 1/5/2008 NO NO NO NO
    6 1/6/2008 YES NO NO NO

    B1:B4 would not meet this criteria because D2 and E2 fall in the middle of this yes string.

    B3:B6 would meet this criteria. Any set of numbers that do meet this criteria need to be recorded with the last date that string falls on, the number of uninterupted YES's in that string, and the catagorie it falls under.

    In this example, I need something like:
    DATE_________No of Occurences/Catagorie
    1/6/2008_______________3B


    After multiple entries, it would look something like this:
    1/ 6/2008______________3B
    1/13/2008______________3A
    1/19/2008______________3D
    2/ 4/2008______________4C

    Can something like this be done?
    Last edited by VBA Noob; 12-28-2008 at 06:40 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    This macro might help. It seems to be easier to start at the bottom and work upwards.

    Sub Test()
    For N = Cells(65536, 1).End(xlUp).Row To 3 Step -1
        For M = 2 To 5
            If Cells(N, M) = "YES" Then
                YesCount = 1
                Counter = 1
                Do While (Cells(N - Counter, M) = "YES" Or (Cells(N - Counter, M) = "NO" And Application.CountIf(Range(Cells(N - Counter, 1), Cells(N - Counter, 4)), "YES") = 0))
                    Counter = Counter + 1
                    If Cells(N - Counter, M) = "YES" Then YesCount = YesCount + 1
                    If N - Counter = 1 Then Exit Do
                Loop
                If YesCount >= 3 Then
                    Cells(65536, 7).End(xlUp).Offset(1, 0) = Cells(N, 1)
                    Cells(65536, 7).End(xlUp).Offset(0, 1) = YesCount & Chr$(M + 64)
                End If
            End If
        Next M
        N = N - Counter
    Next N
    End Sub
    You can then sort your data by date.
    Martin

  3. #3
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    Thanks

    Thank you!

  4. #4
    Registered User
    Join Date
    05-14-2008
    Location
    Southern Illinois
    MS-Off Ver
    2007
    Posts
    56

    Solved

    Thanks
    SOLVED

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Purely as a heads up (given resolved) given changes made in 2007 it's now best to use Rows.Count as opposed to 65536:

    eg this:
    For N = Cells(Rows.Count, 1).End(xlUp).Row To 3 Step -1
    as opposed to this:
    For N = Cells(65536, 1).End(xlUp).Row To 3 Step -1
    This is purely down to the fact that 2007 has 1 million plus rows and thus you can not guarantee 100% of the time that the 65536 method will work pending version etc.... the Rows.Count method is essentially failsafe
    (the same is true re: Columns.Count etc...)

+ 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