+ Reply to Thread
Results 1 to 11 of 11

A function for calculate the cells takes to appear each element

  1. #1
    Registered User
    Join Date
    05-15-2008
    Posts
    38

    A function for calculate the cells takes to appear each element

    Hello,
    I want to obtain from some elements the number of cells it takes to appear:
    We have for example A,B,C, and D,
    and they appear in the next order:

    1 A
    2 C
    3 D
    4 A
    5 D
    6 B
    7 C
    8 A
    9 A

    What I want to know is how much last in appear each element.

    1 A 1
    2 C 2
    3 D 3
    4 A 3
    5 D 2
    6 B 6
    7 C 5
    8 A 4
    9 A 1

    For example, the first “A” last one in appear, but the next element “C” last two in appear. In the forth line again cames the “A”, then are three cells. The “C” was in the cell2, and cames again in the seventh cell, then it takes five cells. In the cells eight and nine are two “A”, then in the cell nine takes one cell in appear again.


    Thank you very much,
    regards

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Could you attach an example workbook showing the original data and what your desired result should be?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Maybe like this:
    Please Login or Register  to view this content.
    The row above the data is necessary for the formulas.

    The formula in B2 and copied down is =IF(COUNTIF(A$1:A1, A2) = 0, ROW() - 1, ROW() - MATCH(2, 1 / (A$1:A1=A2) ) ) - ROW($A$2) + 2


    This is an array formula, meaning it MUST be confirmed with Ctrl+Shift+Enter, not just Enter. (With the cursor in the formula bar, hold down Ctrl and Shift, then press Enter.) You'll know you did it correctly if curly braces appear around the formula in the Formula Bar; you cannot type in the braces directly.

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Assuming that A1:A9 contains the data, try...

    B1, confirmed with CONTROL+SHIFT+ENTER, and copied down:

    =IF(COUNTIF($A$1:A1,A1)>=2,SUM(LARGE(IF($A$1:A1=A1,ROW($A$1:A1)),{1,2})*{1,-1}),ROWS(B$1:B1))

    Hope this helps!

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Assuming that your data is in column A, put 1 in B1 and put this array formula in B2 and drag down .

    =ROW()-MAX(--($B$1:B1=B2)*ROW($B$1:B1))

    Array formulas are confirmed with Ctrl-Shift-Enter (Cmd+Return for Mac)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    05-15-2008
    Posts
    38

    Thank you very much

    Thank you very much, altough I can't make it works. I'm trying doing what you told me, but I can't make works an array formula.
    I put a new thread trying to understand what is the problem:

    http://www.excelforum.com/showthread.php?t=644566

    Regards

  7. #7
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Have a look at the attached sample. I assumed that A2:A10 contains the data,
    I entered the following formula in B2, I confirmed the formula with CONTROL+SHIFT+ENTER, not just ENTER, and then I copied/dragged the formula down the column...

    =IF(COUNTIF($A$2:A2,A2)>=2,ROW()-LARGE(IF($A$2:A2=A2,ROW($A$2:A2)),2),ROWS(B$2:B2))

    Hope this helps!
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-15-2008
    Posts
    38
    Thank you Domenic,
    With the sample you give me It works.
    There are two errors I was doing:
    1) in my program the separate of the formulas is an ";" instead of a ",". That was one of the reasons that gives error for the formulas.
    2) The translation. If I don't translate to spanish, or I translate it bad, it doesn't work. In your formula, Domenic:

    =IF(COUNTIF($A$2:A2,A2)>=2,ROW()-LARGE(IF($A$2:A2=A2,ROW($A$2:A2)),2),ROWS(B$2:B2))

    I did translate for this:

    =SI(CONTAR.SI($A$2:A2;A2)>=2;FILA()-LARGO(SI($A$2:A2=A2;FILA($A$2:A2));2);FILAS(B$2:B2))

    but when I open the worksheet you send, it appears like this:

    =SI(CONTAR.SI($A$2:A2;A2)>=2;FILA()-K.ESIMO.MAYOR(SI($A$2:A2=A2;FILA($A$2:A2));2);FILAS(B$2:B2))

    I thought that "Large" has to be translate as "Largo", but, I don't know why, it has to be translate as "K.ESIMO.MAYOR"...

    Thank you very much

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    For your information, LARGO is for LEN in Excel english (ie. Length).

    according to this site: http://cherbe.free.fr/traduc_fonctions_xl97.html
    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.

  10. #10
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474
    Quote Originally Posted by caldera55
    Thank you Domenic,
    You're welcome!

    I thought that "Large" has to be translate as "Largo", but, I don't know why, it has to be translate as "K.ESIMO.MAYOR"...
    I'm not familiar with non-English versions of Excel, but it looks like the correct translation is K.ESIMO.MAYOR, at least as far as Excel is concerned.

  11. #11
    Registered User
    Join Date
    05-15-2008
    Posts
    38
    Yes, finally it is K.ESIMO.MAYOR, Dominic.

    Very useful for me that link of translate functions, NBVC.

    Thank you very much to both.

+ 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