+ Reply to Thread
Results 1 to 10 of 10

Comparing 2 colums and if match replace or provide value from the other column

  1. #1
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Comparing 2 colums and if match replace or provide value from the other column

    Hi All,

    I have one column with a data that can repeat for example:

    Column A

    markg
    danielw
    robertx
    danielw
    sylviaz
    markg
    ...

    on the other column I will have following information

    Column C and D here values are only once
    C D
    markg | Mark Gold
    danielw | Daniel Walsh
    robertx | Robert Xmen
    sylviaz | Sylvia Zet

    I need big help to create function in VB (I use Excel 2010) that will take first colum A as range each cell from column A (A1,A2,...) will be compared with Column C to find a match where find the match replace with full name from column D.

    Can you please help is it possible and where to start.

    Thank you very much in advance for your help and time.

    Regards,
    Daniel

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Please Login or Register  to view this content.
    I havent tested this.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Thank you very much for your reply.

    Can you please advise how to covert this to function () with 2 arguments 1 range to search second to compare.

    For example :

    Function test(s,c)

    Dim r As Excel.Range

    Set r = Range("a1:a10")

    For Each c In r.Cells
    strReplace = ""

    On Error Resume Next
    strReplace = Cells(Application.WorksheetFunction.Match(c.Text, Range("a:a"), 0), 4)
    On Error GoTo 0

    If strReplace <> "" Then c.Text = strReplace
    Next c

    End Function

    Unfortunately at the moment give me Run-time error'1004'

    Regards,
    Daniel

  4. #4
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Hello Dalton. Run the below sub. I've tested it and it does was you requested.

    If a name in column A match column C, then Replace the name in column C with the full name which is next to it in Column D. Let me know how it works for you.

    Please Login or Register  to view this content.
    Last edited by playaller; 05-15-2014 at 12:26 PM. Reason: Shortened Code


    Shelton A.
    If Helpful, Add Reputaion!

  5. #5
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Hi Shelton,

    This is absolutely brilliant, thank you very much.

    Can I ask for small change or explanation.

    1. The function change the values in column C. In my version column C and D will be a key to check (single login and name assigned) and column A should updated.

    As you can see in column A login can appear multiple time and in this case the full name should appear multiple times.

    2. Can this function be build so i could pick column that need to be updated and the ranged of 2 columns against which will be checked.

    3. As you can see I am very new to this and forum user can you explain how to rate your answer because it is brilliant and super fast.

  6. #6
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Comparing 2 colums and if match replace or provide value from the other column

    So are you saying if C matches D, update C with value from column A? I can't create a macro with settings for you if I don't understand your excel layout because now it seems that you have changed the layout and the specific request to another.

    You can try to adjust this where:

    COLm1 = "A" ' Original Matching Row
    COLu = "C" ' Update this column if match
    COLr = "D" ' Replace with Value from this column but same row of match



    Please Login or Register  to view this content.
    Last edited by playaller; 05-15-2014 at 01:22 PM. Reason: Updated description

  7. #7
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Hi Shelton,

    I agree my explanation is not clear (please see attached file) this is not live example but it will look similar.

    I hope in the attached file it will be more clear.

    Thank you again for your help.

    Regards,
    Daniel
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Okay now it's clear! Thank you for providing an example. Let me know how it works for you.

    Use this code:

    Please Login or Register  to view this content.
    Last edited by playaller; 05-16-2014 at 10:16 AM. Reason: Cleaned up column after update

  9. #9
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Hi Shelton,

    Thank you very much for your help, I have rated this post as Excellent.

    Your knowledge about VB is great.

    Regards,
    Daniel

  10. #10
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Comparing 2 colums and if match replace or provide value from the other column

    Thank you Daniel! Glad I could help.

+ 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. Formula required for comparing multiple colums to multiple colums
    By Pringgles in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-30-2012, 07:23 AM
  2. Comparing 2 columns- if a match is found return a value in 3rd column
    By lineson in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 12-20-2011, 04:48 PM
  3. Comparing 2 colums in 2 sheets
    By StepanieB in forum Excel General
    Replies: 3
    Last Post: 07-04-2009, 03:39 PM
  4. Comparing 2 colums
    By bwian in forum Excel General
    Replies: 3
    Last Post: 06-08-2009, 11:16 AM
  5. Comparing 2 colums of data
    By Sara_UK in forum Excel General
    Replies: 6
    Last Post: 09-28-2006, 06:51 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