+ Reply to Thread
Results 1 to 10 of 10

Counting adjacent cells?

  1. #1
    Registered User
    Join Date
    09-19-2013
    Location
    Corfu
    MS-Off Ver
    Excel 2007
    Posts
    5

    Counting adjacent cells?

    Hi there!!!

    I've got the following situation and need help:

    In column of an Excel spreedsheet -let's say coloumn A- I have the following:

    Column A
    Blanck Cell
    Blanck Cell
    1
    1
    Blanck Cell
    Blanck Cell
    1
    1
    Blanck Cell
    1
    1
    1
    Blanck Cell
    Blanck Cell
    ...
    1
    Blanck Cell etc...

    I want to count the number of the 1's occuring 1time, 2times,3 times etc consecutively. Based on the given example the number of 2 adjacent 1's is 2 because 2 adjacent 1's appears 2 times.

    Thank you...

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Counting adjacent cells?

    Maybe check out the areas function.

    Here is something I did using VBA years ago, I didn't use the count function though.
    http://www.davesexcel.com/vbacodes.htm#858291122

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Counting adjacent cells?

    Assuming your data starts on A2, down, try this. In B2, copied down...
    =IF(A2="","",IF(A2=A1,SUM(B1,1),1))
    Then create a table something like this...
    E
    F
    2
    Number Count
    3
    1
    1
    4
    2
    2
    5
    3
    2
    6
    4
    1
    7
    5
    0

    In F3, copied down...
    =COUNTIF(B:B,E3)-COUNTIF(B:B,E4)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert RobertMika's Avatar
    Join Date
    06-22-2009
    Location
    Haverhill, UK
    MS-Off Ver
    Excel 2003-13
    Posts
    1,530

    Re: Counting adjacent cells?

    =SUMPRODUCT(--((FREQUENCY(IF(A2:A20=C2,ROW(A2:A20)),IF(A2:A20<>C2,ROW(A2:A20))))=D2))
    frequency.xlsx
    Confirm COntrl+shift+Enter
    If you are http://www.excelforum.com/image.php?type=sigpic&userid=125481&dateline=1392355029happy with the results, please add to the contributor's
    reputation by clicking the reputation icon (star icon).




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.
    To undo, select Thread Tools-> Mark thread as Unsolved.
    http://www.excelaris.co.uk

  5. #5
    Registered User
    Join Date
    09-19-2013
    Location
    Corfu
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting adjacent cells?

    Thanks, the last solution with sumproduct worked well. I was trying to figure out why it works.... Can you explain to us RobertMika why? (if it doesn;t bother you give us a few details). What about if I have the mark "X" instead of blank cells between data? How can I use then your formula?

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting adjacent cells?

    Since the formula has to be array entered** you may as well just use SUM:

    =SUM(IF(FREQUENCY(IF(A2:A20=C2,ROW(A2:A20)),IF(A2:A20<>C2,ROW(A2:A20)))=D2,1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting adjacent cells?

    Quote Originally Posted by Miltos01 View Post
    What about if I have the mark "X" instead of blank cells between data? How can I use then your formula?
    Since you're counting consecutive cells that contain the number 1, X's instead of empty cells won't make a difference.


    Data Range
    A
    B
    C
    D
    1
    2
    X
    1
    1
    3
    X
    2
    2
    4
    1
    3
    1
    5
    1
    4
    0
    6
    X
    7
    X
    8
    1
    9
    1
    10
    X
    11
    1
    12
    1
    13
    1
    14
    X
    15
    X
    16
    X
    17
    1
    18
    X
    19
    20




    This array formula** entered in D2 and copied down:

    =SUM(IF(FREQUENCY(IF(A$2:A$20=1,ROW(A$2:A$20)),IF(A$2:A$20<>1,ROW(A$2:A$20)))=C2,1))

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  8. #8
    Registered User
    Join Date
    09-19-2013
    Location
    Corfu
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting adjacent cells?

    Tony Valko, thanks again for your help... It's perfectly understood!!! The formula works like a charm...

    What about if I have the following situation:

    Shorting.jpg

    How you hand these?

    Thanks again for your replies....

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Counting adjacent cells?

    Quote Originally Posted by Miltos01 View Post
    Tony Valko, thanks again for your help... It's perfectly understood!!! The formula works like a charm...
    Good deal!

    What about if I have the following situation:

    Attachment 267264

    How you hand these?

    Thanks again for your replies....
    I don't understand what you want with that?

  10. #10
    Registered User
    Join Date
    09-19-2013
    Location
    Corfu
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Counting adjacent cells?

    After multiple occurances of number draws some patterns arise...and I want to study those patterns as far as their shape...The shape of a pattern is a trend. Maybe those patterns in some cases can be valuable for understanding formation and in some cases predict results!

    Thanks again...
    Last edited by Miltos01; 09-24-2013 at 04:15 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Counting blanks in non-adjacent cells
    By ClickingNoise in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-20-2013, 08:46 AM
  2. Counting Cells with data in adjacent Cells
    By Alvin Hunter in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2013, 03:38 PM
  3. Counting adjacent cells(text) to equal one value
    By Calithea in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-29-2012, 04:08 AM
  4. counting adjacent cells that match a criteria
    By chrisvacek in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-11-2012, 11:44 AM
  5. Duplicate counting adjacent cells
    By Wizard33 in forum Excel General
    Replies: 5
    Last Post: 03-16-2010, 06:31 PM

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