+ Reply to Thread
Results 1 to 14 of 14

Count Consecutive Repeating Words

  1. #1
    Forum Contributor
    Join Date
    06-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    106

    Count Consecutive Repeating Words

    Hi all

    I need to keep a count of either the word “UP” or “DOWN” in column H and keep a running tally for the word “UP” in Column K and the word “DOWN” in Column T. But there’s consecutive UP’s or DOWN’s in column H and I only want to see the total in Column K, so that’s why I'm thinking I probably need a macro. However, I’m open to any other way of completing the task.

    By the way, I was doing this manually and it took me a few hours for 500 entries, but I’ve got to complete multiple workbooks of 5,000 entries. Yikes!

    I’ve attached a sample sheet so you can see the desired results. I will always start in cell H2 and end in the last cell in H.

    If at all possible, anyone that provides the code, could you please place a couple notes in the macro so I can figure it out. I have the "Excel VBA For Dummies" book and just got the "VBA and Macros: Microsoft Excel 2010" but still haven't read all of it, but would like to understand the commands being used.

    Thanks and any assistance is very much appreciated!
    Attached Files Attached Files
    Last edited by ExcelQuestFL; 08-16-2010 at 02:29 PM.

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

    Re: Count Consecutive Repeating Words

    Do you explicitly need the values in the first row of the streak ?
    (rather than the last which might be a bit quicker to calculate)

  3. #3
    Forum Contributor
    Join Date
    06-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    106

    Re: Count Consecutive Repeating Words

    The last row in the streak will work just fine.

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Count Consecutive Repeating Words

    Try:

    =IF(AND($H2=K$1,$H1<>K$1),MATCH(TRUE,INDEX($H3:$H$36<>K$1,0),0),"")

    adjust ranges to suit and copy down and to next column if you have "down" in L1
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Count Consecutive Repeating Words

    Here:

    =IF(H1="UP","",IF(H2="UP",MATCH("DOWN",H3:$H$36,0),""))

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

    Re: Count Consecutive Repeating Words

    Quote Originally Posted by ExcelQuestFL View Post
    The last row in the streak will work just fine.
    In which case - given the volume of data perhaps:

    K2:
    =IF(OR($H2<>K$1,$H2=$H3),"",COUNTIF($H$2:$H2,K$1)-SUM(K$1:K1))
    copied down and applied to Col T

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Count Consecutive Repeating Words

    If you are going to use the first in the streak, and if you only have UP and DOWN options, then zbor's is superior over mine... but if you have multiple text strings and you want to find streak of one, then mine should work.. or for last in streak, DO's.

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

    Re: Count Consecutive Repeating Words

    Quote Originally Posted by NBVC
    if you only have UP and DOWN options, then zbor's is superior over mine
    I think zbors will fail for either/or column depending on the last value be it UP/DOWN

  9. #9
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Count Consecutive Repeating Words

    well yes... But only in case of one last UP (DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN,UP) other will give 1 or more so error can be ignored

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Count Consecutive Repeating Words

    Quote Originally Posted by DonkeyOte View Post
    I think zbors will fail for either/or column depending on the last value be it UP/DOWN
    I guess mine too

    To adjust for that, make the range in the formula one row larger than the database.

    i.e.

    =IF(AND($H2=K$1,$H1<>K$1),MATCH(TRUE,INDEX($H3:$H$37<>K$1,0),0),"")

    copy down and to next column.

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

    Re: Count Consecutive Repeating Words

    Quote Originally Posted by zbor
    well yes... But only in case of one last UP (DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN, DOWN,UP) other will give 1 or more so error can be ignored
    If the last value in the column matches the header you will get an error irrespective of streak length - it follows that the last calculation in one of the two columns will fail.

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Count Consecutive Repeating Words

    Yes.. I ment in all other cases you'll get correct answer only in this case you get #N/A instead of 1....

    But yes, can and should be avoided

  13. #13
    Forum Contributor
    Join Date
    06-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    106

    Re: Count Consecutive Repeating Words

    Wow that was incredibly fast and thanks very much for the replies guys!

    I'm using DO's solution as I'm getting the correct results and I think with a little work, I'll be able to figure out the formula. TBH I was getting kind of confused reading NBVC's and Zbor's formulae, but will still try and figure them out too bc the results on the sample looked ok as well.

    Thanks again DO and friends!!

    EDIT: Just saw the discussion above my last post. I only tested in NBVC's and Zbor's on the first UP heading in Column K...didn't test Column T. DO's for sure works in both columnds.

  14. #14
    Forum Contributor
    Join Date
    06-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    106

    Re: Count Consecutive Repeating Words

    Wow Excel is great! I just completed one workbook with 5507 entries in 1 minute. Excellent!!

+ 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