+ Reply to Thread
Results 1 to 9 of 9

Search for value, and then copy value in adjacent column

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Search for value, and then copy value in adjacent column

    Hello

    I have a column with many different 4 letter values in column B (about 6000 rows all up), in column A I have cases which can either be A or B, I am looking for a formula in column C that searches for one particular 4 letter value in col B, and then copies "1" into all the rows above where the case is the same as the case adjacent to the target 4 letter value, and copies "2" into all the rows above where the case is different to the case next to the adjacent target 4 letter value. Then, search for the nexy time that the 4 letter value appears, and repeat the step working back up the list until the last time that the target 4 letter value appeared.

    I apologise for the confusing description, I have attached an example spreadsheet which should make things clearer.

    To state simply, find everytime where the 4 letter value "YEST" appears in col B, check if it is case A or B in the adjacent cell in col A, and then place a "1" in col C for each case above the "YEST" value that matches the case next to the "YEST" value, and a "2" next to each case that does not match the case appearing next to the "YEST" value. Once this is done, move onto the next "YEST" value down and repeat the process (bearing in mind that a different case could appear next to the "YEST" value).

    I understand this quite a complex problem, but any assistance would be gratefully received

    T15K
    Attached Files Attached Files

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

    Re: Search for value, and then copy value in adjacent column

    =IFERROR(IF(A2=INDEX(A2:$A$50,MATCH(TRUE,B2:$B$50="YEST",0)),1,2),"")
    Confirm Contrl+Shift+Enter
    Drag down
    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

  3. #3
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Search for value, and then copy value in adjacent column

    Thank you for the excellent solution.

    Could I ask you to add another layer of complexity to the formula? Basically, I would like to include a second target code in Col B. For example, if "TMRW" appears, then repeat the process described earlier with the values 3 and 4. So now if "YEST" appears, we want to copy up 1 or 2, depending on whether the case matches Column A, and if "TMRW" appears, do the same thing but with 3 or 4, depending on whether the case matches. These values would be copied up until either "YEST" or "TMRW" appears again.

    Is it possible to add this extra criteria into the formula?

    Many thanks for your assistance so far

    T15K

  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: Search for value, and then copy value in adjacent column

    Could you post an example?

  5. #5
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Search for value, and then copy value in adjacent column

    I have attached a sample spreadsheet. Basically what I am after is similar to the first formula, however there are now two possible target codes "YEST" and "TMRW", each with different values (1 and 2, or 3 and 4, respectively). Otherwise, same process, copy the values upwards for case A and B, depending on whether it matched the target word.

    Thanks
    T15K
    Attached Files Attached Files

  6. #6
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Search for value, and then copy value in adjacent column

    I am also interested in this answer.
    Many thanks to all who have helped me.

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

    Re: Search for value, and then copy value in adjacent column

    Example spreadsheet.xlsx
    With helper columns
    (this could be combine into one single formula but ww will loose the clarity)

    BTW.Quite intresting problem

  8. #8
    Registered User
    Join Date
    07-10-2012
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Search for value, and then copy value in adjacent column

    Great, that works perfectly. Thank you very much.

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

    Re: Search for value, and then copy value in adjacent column

    You are welcome.please add reputation.

+ 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: 2
    Last Post: 12-14-2012, 11:45 PM
  2. Search for Word and Copy Adjacent Cell(s)
    By BrittanyK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2011, 04:05 PM
  3. Replies: 1
    Last Post: 07-26-2011, 06:48 AM
  4. Search and copy adjacent cells
    By bennimartin in forum Excel General
    Replies: 1
    Last Post: 12-14-2010, 02:11 AM
  5. Search column, return values in adjacent column?
    By HELPME13 in forum Excel General
    Replies: 3
    Last Post: 10-01-2010, 11:17 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