+ Reply to Thread
Results 1 to 3 of 3

Count the value of a cell within a range only if it is adjacent to a specific value

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    Wilson, Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    2

    Count the value of a cell within a range only if it is adjacent to a specific value

    Hi,

    For simpleness I will list a very small range of A1:C10 In each cell I have one letter signifying a color code. For instance, cell A1 has a value of "b". Cell B1 has a value of "c". This might repeat in cells B10 and C10. I can manually look at the cells and count them. There would be two, but I want Excel to search and count the two values within my range for me, because... as the range expands I could miss a count.

    FYI: If I have nine cells A1:C3, and in cell B2 I have "b", I don't care which cell "c" is in, as long as it is adjacent to the cell with a "b", I would like Excel to count it as one, but I think that might make the formula more complicated... If it's easier to have Excel look only to the cell adjacent on the right then I'm ok with that as well.

    I know how to do this using two columns at a time, but I want to use a range, so I don't have so many cells with all the formulas. Anyone up to helping me?

    Thank you so much!

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Count the value of a cell within a range only if it is adjacent to a specific value

    This formula will count all instances of a "b" in one cell and a "c" either to right or left within the range A1:C10

    =SUMPRODUCT((A1:B10="b")*(B1:C10="c")+(B1:C10="b")*(A1:B10="c"))

    That may double count, e.g. with "c" in A5, "b" in B5 and "c" again in C5 that will count as 2 because the same "b" has a "c" to both right and left.
    Audere est facere

  3. #3
    Registered User
    Join Date
    02-27-2013
    Location
    Wilson, Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Count the value of a cell within a range only if it is adjacent to a specific value

    That is awesome! Since you are correct where it counted more than I wanted to, I tweaked your formula.

    =SUMPRODUCT((F6:F9="a")*(G6:G9="b")+(H6:H9="a")*(I6:I9="b"))

    I will have to create this formula for every 16 squares and I will also need to change my letters, but hey. I like it!

    Thank you so much!!!

    Here is a picture of my sample project.
    pixel quilt sample.jpg
    Since this is a design to sew, I realized I only needed to find adjacent cells between two columns because I will only sew two at a time.
    Now that you helped me I can modify the column from top of the range to the bottom of the range.

    Nice!

+ 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