+ Reply to Thread
Results 1 to 11 of 11

Replace Cell that matches a cell in another worksheet with the next cell

  1. #1
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Replace Cell that matches a cell in another worksheet with the next cell

    I would like to replace the contents in Cell F in sheet1 if it matches Cell B in sheet2 and replace Cell F on sheet1 with the data in Cell A on sheet2. This needs to be done for the entire column Sheet1 has some 400 rows with duplicates and sheet2 has 120 with the master information. I have been going round and round in circles trying many different codes that I have found but nothing works feeling frustrated any help would be grateful many thanks

    PS
    Cell F in sheet1 = vehicle reg
    Cell G in sheet1 = Vehicle reg - make model

    Cell B in sheet2 = vehicle reg
    Cell A in sheet2 = fleet no

    I dont know if it would be better to use a partial match using Cell G sheet1 with Cell B sheet2 and replace Cell F sheet1 with data from Cell A sheet2.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,996

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    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.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Here is a sample of the workbook there are 3 worksheets Sheet1, Sheet2 & Sheet1 after VBA to to what I am trying to do many thanks for looking at this post
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,996

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Try this (on a copy of your data):

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    TMS many thanks for that I tried it in my sample workbook all works fine so I then tried it in my actual workbook an it works 99.9% as it tends to miss out 4 vehicle reg and does not change them. I have checked to make sure that they are the same which they are i.e. no spaces etc. It is not to much of a hard ship I can work with it but unsure why it misses the same 4 vehicle reg No each time I run it any ideas.

    Many thanks once again for what you have done.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,996

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Possibly leading or trailing spaces on either the source or the target. It is designed such that, if it doesn’t find a match, it leaves the source as is.

    Post a sample workbook with just the problem registrations (source and target).

  7. #7
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    I copied and pasted the vehicle Reg that it missed into my test workbook and it all worked as I said I thought that there may have been a trailing spaces in the sheet2 but there wasn't. I have just checked in sheet1 and there is a trailing spaces in here. The data in sheet1 is downloaded from a work base software as a report so we do not populate it. is there any way round this?? thanks again

    Is there a way to check for trailing spaces and remove them first?
    Last edited by Shades1970; 04-10-2019 at 04:07 AM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,996

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Use Trim.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Many thanks TMS that works a treat all sorted you are the Forum Guru

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,996

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  11. #11
    Registered User
    Join Date
    02-17-2017
    Location
    Cornwall, England
    MS-Off Ver
    2016
    Posts
    23

    Re: Replace Cell that matches a cell in another worksheet with the next cell

    Already Done many thanks again for all you 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. [SOLVED] If a cell matches another cell then check cell to imediate left and perform basic math....
    By Ourkid123uk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2019, 01:04 PM
  2. copy/paste range of cells if cell matches another cell in another worksheet
    By Lewis Shoulders in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-16-2018, 07:30 AM
  3. [SOLVED] If cell matches Cell Range than enter text in another cell
    By BOB MUSE in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-20-2018, 09:32 AM
  4. Replies: 4
    Last Post: 11-03-2017, 10:10 AM
  5. Replies: 2
    Last Post: 01-13-2015, 12:12 PM
  6. Copy cell information from one worksheet if a cell matches the criteria
    By grammydeb52 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-02-2013, 01:00 AM
  7. If cell equals another cell from another worksheet then replace whole row
    By Psychoterapeuta in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2013, 11:22 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