+ Reply to Thread
Results 1 to 7 of 7

Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positions

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    Louisville, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positions

    Hi All, I am trying to search values in column labeled "CPT1" that exists in column labeled "CPT2", if found return the values in column labeled "CPT Values Found" while maintaining the relative positions or matching the positions as those in column labeled "CPT1". The values that do not exist will be called "NF". Also append the respective values of column labeled "MOD2" in column labeled "Mode Values". Please see the data before running macro and after running macro to get my idea clear. Thanks guys, I haven't been here for a while and now losing my vba knowledge.

    Before Macro Run
    Before Macro Run.png

    After Macro Ran
    After Macro Ran.png
    Last edited by pato225; 03-11-2015 at 11:56 PM.

  2. #2
    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
    52,933

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    Why do you need a macro for this? =IF(ISERROR(VLOOUP(C2,$A$2:$B$10,1,0),"NF",VLOOUP(C2,$A$2:$B$10,1,0)) will probably do this for you

    If you still have a problem, upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.
    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

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    Louisville, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    Attached is an Excel File for ease
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    01-15-2013
    Location
    Louisville, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    okay I just did, its going to get more complex I just need a start and will expand the idea from there

  5. #5
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  6. #6
    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
    52,933

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    Put this in J3 and copy down...
    =IF(ISERROR(VLOOKUP($C3,$A$3:$B$11,1,0)),"NF",VLOOKUP($C3,$A$3:$B$11,1,0))
    and this in K3, copied down...
    =IF(ISERROR(VLOOKUP($C3,$A$3:$B$11,2,0)),"",IF(VLOOKUP($C3,$A$3:$B$11,2,0)="","",VLOOKUP($C3,$A$3:$B$11,2,0)))

  7. #7
    Registered User
    Join Date
    01-15-2013
    Location
    Louisville, USA
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Macro - Search/Match Values in a Coloumn and Return values, & maintain relative positi

    Thank you FDibbins and Sixthsense, there are a lot of moving targets that I haven't mentioned. Please look at this excel named "Vba_AutoMatch_Retain Positions". There are variables I want to account for, for example in column "F" (CPT2) 0042T has 2 duplicates and column J (Mod2) has corresponding values that indicates that 0042T can be by itself, or a value of 80 or a value of 82. So I was thinking I could add columns G (Found CPT1 Values in CPT2) where the search values of columns A (CPT1) are returned, append their corresponding values in column B (Mod1) into column H (Append Corresponding Mod1) before I even start looking at column C to start another comparison. I guess my other question is what happens when there is only one value of 0042T in column A and 3 values in column F? So I am thinking of what kind of return I will need in these case. So that's why I am saying it is getting a little complex even difficult for me to explain. But essentially I just want to search the first column (column A) and if they exist in Column F, then I will first append their corresponding values in column B while maintaining the relative positions. But that issue of the duplicated values will always pop-up. Also will the search method account for when there are corresponding duplicates in both columns A and F. Attached is the true spreadsheet I am playing with may be this will give you guys an idea what the data looks like.

    Thanks again.

    I have a hard time explaining but this is the best explanation I can come up with.
    Attached Files Attached Files

+ 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] Return Multiple values from a column with index and match, and search criteria
    By marcusduton in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 02-15-2015, 09:59 PM
  2. Is there a formula that will search for nonspecific values and return a match?
    By Yodaman1997 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-23-2014, 05:03 PM
  3. Replies: 7
    Last Post: 08-04-2013, 03:41 PM
  4. [SOLVED] How to return multiple values that match a single search criteria?
    By JSallen in forum Excel General
    Replies: 4
    Last Post: 11-28-2012, 11:49 AM
  5. Return ALL relative positions of a value within an array
    By bekaii in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-19-2007, 07:37 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