+ Reply to Thread
Results 1 to 11 of 11

Last occurence of a random element in cell in column

  1. #1
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12

    Last occurence of a random element in cell in column

    Hello everyone,

    My name is Maico and I need some help with my thesis and I cannot seem to make it work.

    I am working on a problem with cells and columns.

    It can be that I have a column with concatenated cells as follows:
    4
    4-8
    4-8-3
    2-4-8-3
    1-4-8-3-5
    -
    -
    -
    9
    9-6
    7-9-6
    -

    The column next to the above one gives certain numbers for capacity, for example
    100
    200
    300
    400
    500
    -
    -
    50
    150
    250
    -

    I want to give an number as input and receive back from the formula the complete cell next to the one that corresponds with the latest occurence of the input in the cell.
    This means that, if the input is 6, my output would be the value of the cell next to 7-9-6, the one with the capacity, since this is the last occurence of a 6. If my input is 4, I want my output to be the value of the cell next to the one with 1-4-8-3-5.
    The formula should work for any number as input, since it is coming from a generated column and is random of length. Also, the number of empty rows (with -) differs, sometimes 1, sometimes 2 but it can also be 100.

    This means that the column can be
    4
    6
    5
    but the column is most likely really long, maybe like 1000, or more

    I want my output then to be
    500
    250
    500

    because these are the corresponding contents in the column next to the one with
    1-4-8-3-5
    7-9-6
    1-4-8-3-5

    becuaes these are the latest occurences of the numbers 4, 6 and 5.
    I have been trying to use the index function and more things but I just cannot seem to make it work.
    All the help is appreciated

    Cheers,
    Maico

  2. #2
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12

    Re: Last occurence of a random element in cell in column

    In addition:

    Sorry that I didn't post my file, it is really a mess.
    I think it is quite understandable from this.
    Any feedback would also be welcome

  3. #3
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: Last occurence of a random element in cell in column

    As modeled in the attached, a formula that will work is: =INDEX(B2:B13,AGGREGATE(14,6,(ROW(A$2:A$12)-ROW(A$1))/(ISNUMBER(SEARCH(C1,A2:A12))),1))
    Input the number for which you wish to search into cell D2.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  4. #4
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12

    Re: Last occurence of a random element in cell in column

    Hello JeteMC,

    Sorry for the slow response but it worked very well as I was asking, so thank you very much for that.

    Unfortunately, I found something that I cannot fix, so I hope you, or someone else, can also help me out with that.
    When you download the file, and you change the concatenated column from
    4
    4-8
    4-8-3
    2-4-8-3
    1-4-8-3-5
    -
    -
    -
    9
    9-6
    7-9-6
    -

    to

    4
    4-8
    4-8-3
    2-4-8-3
    1-4-8-13-5
    -
    -
    -
    9
    9-6
    7-9-6
    -

    The difference is in the number 3, which I changed in the last column once to the number 13.
    If I search, in this file, then for the last occurence of the number 3, it will give me the number corresponding to the cell in which there is 13, instead of the one with 3 alone.
    So the problem is that I need to find the corresponding value of something in between two dashes (-), instead of only finding the number 3, because it does not do it correct.
    I need to be able to do this for one digit, two digit and three digit numbers. So sometimes with 1, sometimes with 2, and sometimes with 3, random, so it needs to work in all cases.

    Next to that, I discovered something else that I can not seem to be able to fix..

    The problem is that I have the concatenated cell like this
    4-87-9-1-43
    In this cell, and in any random cell, I need to extract the very first number with a formula, and in another formula the very last number.
    So in this case, one formula should give me the number 4 and the other should give me 43.
    Also this should work with one, two and three digit number that can be random at both the beginning and end.
    So this basically means everything before the first dash (-) and everything after the last dash (-)

    It seems that I am not advanced in Excel, so that is why I am requesting your help..

    All help is appreciated. I am so much stuck...

    Cheers,
    Maico

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: Last occurence of a random element in cell in column

    This proposal employs a number of helper columns which may be moved and/or hidden for aesthetic purposes.
    The helper columns are populated using: =TRIM(MID(SUBSTITUTE($A2,"-",REPT(" ",LEN($A2))),(F$1-1)*LEN($A2)+1,LEN($A2)))
    Note that F1:K1 are populated manually. (type 1 in F1 and 2 in G1 > select both > drag the fill handle over)
    The formula in cell E2 is: =INDEX(B2:B13,AGGREGATE(14,6,(ROW(A$2:A$13)-ROW(A$1))/(SEARCH(D2,F2:K13)=1),1))
    Let us know if you have any questions.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12
    Hello,

    I'm working now on the file and I noticed that it does not work yet for numbers like 10,20,30 and 40. Do you know how I can fix this myself?

    Also, in my previous post I was asking if it was possible to always extract the first full number before the first dash (-) and the last full number after the last dash (-). I also can't find the answer to that still. I believe that it is not in the file.
    Please correct me if I am wrong.

    All help is appreciated!
    Cheers,
    Maico

  7. #7
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12
    I added a screenshot where I am searching for 3 and I get the one from 30

    Quote Originally Posted by Maicoooooo View Post
    Hello,

    I'm working now on the file and I noticed that it does not work yet for numbers like 10,20,30 and 40. Do you know how I can fix this myself?

    Also, in my previous post I was asking if it was possible to always extract the first full number before the first dash (-) and the last full number after the last dash (-). I also can't find the answer to that still. I believe that it is not in the file.
    Please correct me if I am wrong.

    All help is appreciated!
    Cheers,
    Maico

  8. #8
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Last occurence of a random element in cell in column

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: Last occurence of a random element in cell in column

    Two changes.
    1. Modify the formula in F2:K13 to read: =VALUE(TRIM(MID(SUBSTITUTE($A2,"-",REPT(" ",LEN($A2))),(F$1-1)*LEN($A2)+1,LEN($A2))))
    2. Modify the formula in E2 to read: =INDEX(B2:B13,AGGREGATE(14,6,(ROW(A$2:A$13)-ROW(A$1))/(F2:K13=D2),1))
    Let us know if you have any questions.

  10. #10
    Registered User
    Join Date
    04-21-2019
    Location
    The Netherlands
    MS-Off Ver
    2013
    Posts
    12

    Re: Last occurence of a random element in cell in column

    Goodmorning again,

    Thanks for the help, it seems to work out all fine. I appreciate it very much

    In the meantime, I have been trying to make some progress in my thesis but I stumbled upon some new problems.

    Since someone asked me to always send a file with the question, I believe that is what I have added now.



    In the sheet, you can find the problem as described before, with concatenated cells corresponding to routes.

    What I would now like to build automatically, is something I have now just typed in the two tables from E1 to G5, and fro0 I1 to J4.

    For table 1, I want to make an automatic table which numbers the final routes. This means that the table should only include routes that are final, and not any intermediate routes, since they are not finished yet
    They can be numbered like I did now for example, like 1, 2,3 and so on. The problem, again, is that there can be for example 60 routes in total and it needs to build it automatically with only the routes that are final.

    For table 2, I would like to see which values are not included in the final routes yet. In this case, it is about numbers 2 and 15. What I can think of for example is to add a number in cell K1 which in here is 15, corresponding to the total number of clients.
    In table 2 then, the numbers from 1 up to 15 should be displayed, if and only if they are not used in table 1, column F.


    I would appreciate the help, because you guys are helping me out so much!

    Cheers,
    Maico
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,554

    Re: Last occurence of a random element in cell in column

    As to table 2 this proposal expands what I suggested earlier.
    1. Modify the helper column formula to read: =IFERROR(VALUE(TRIM(MID(SUBSTITUTE($A3,"-",REPT(" ",LEN($A3))),(O$1-1)*LEN($A3)+1,LEN($A3)))),"")
    2. Populate column L by typing the number 1 in L1 then for L2 down use: =IF(SUM(L1,1)<=K$1,SUM(L1,1),"")
    3. Populate column M using: =SUMPRODUCT(--(O$3:T$16=L1))
    4. Populate column J using: =IFERROR(AGGREGATE(15,6,L$1:L$16/(M$1:M$16=0),I2),"")
    As for table 1, I initially thought that a route was finalized when the number in column E appears for the final time in column A. This appears to not be the case as there is no 2 in column A.
    Please include an explanation of what finalizes a route and what distinguishes one route from another.
    Let us know if you have any questions.

+ 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. Replies: 6
    Last Post: 08-07-2018, 09:25 AM
  2. [SOLVED] Formula for Data with random element
    By debora in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-05-2014, 06:35 AM
  3. [SOLVED] Row number of Nth occurence in a column
    By par0016 in forum Excel General
    Replies: 3
    Last Post: 06-08-2012, 10:35 AM
  4. Replies: 2
    Last Post: 03-21-2012, 12:28 PM
  5. occurence /count of a cell value in a column/range
    By ankurzvohra in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2008, 12:59 AM
  6. Pull random cell on column B if column C is empty
    By curb in forum Excel General
    Replies: 1
    Last Post: 04-08-2008, 04:57 PM
  7. how do i map an excel column to an XML element
    By john dunford in forum Excel General
    Replies: 0
    Last Post: 05-23-2005, 08:06 AM

Tags for this Thread

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