+ Reply to Thread
Results 1 to 6 of 6

Looping 'find' to find a value and replace a value in an adjacent column

  1. #1
    Registered User
    Join Date
    07-05-2016
    Location
    Nottingham
    MS-Off Ver
    2010
    Posts
    12

    Looping 'find' to find a value and replace a value in an adjacent column

    Hi,

    I'm sure this should be simple, but I can't seem to get it to work!

    I have a worksheet with over 60000 rows. There is a column which contains a product and a column offset by 2 from the product which contains the product type.

    For 15 products, the product type isn't correct and needs replacing with the same product type for all 15.

    I have put the 15 products into an array, thinking it would be easier to loop through the array for each find, I maybe wrong!

    Problem I have is, is that I am unable to work out how to loop through all the products and change the column offset by two rather than the found cell itself! I managed it for the first product but then got stuck in a continuous loop as it kept refinding the same product!

    Any help would be appreciated!

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Looping 'find' to find a value and replace a value in an adjacent column

    I would guess it is a simple fix, and I would also guess that if you are not familiar with arrays they are NOT easier. They are DEFINITELY faster though.
    It seems that a vlookup on a reference table for 15 items and IF the lookup returns a value then replace whatever needs to be replaced, otherwise next... but I cant help much without specifics.

    Attach a sample workbook. 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.
    Last edited by mikeTRON; 09-12-2016 at 06:39 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Looping 'find' to find a value and replace a value in an adjacent column

    It sounds like this is a one time problem.
    Excel's FIND should find each of the Products and then you can manually change their types.
    Or perhaps AUTO-Filter
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Looping 'find' to find a value and replace a value in an adjacent column

    Quote Originally Posted by mikerickson View Post
    It sounds like this is a one time problem.
    Excel's FIND should find each of the Products and then you can manually change their types.
    Or perhaps AUTO-Filter
    Yeah except it seems the OP wants to not find and replace, but find then replace TWO columns to the right.
    So OP COULD filter on each of the 15, and just copy and paste over whatever is in the cells that need to be corrected.

    I would likely do that instead of creating code, but looping through with a CASE statement also wouldnt be very difficult IF you wanted to learn in VBA or IF you had to do this multiple times in the future.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Looping 'find' to find a value and replace a value in an adjacent column

    If I were coding this, I'd use Find rather than a Filter.

    Outer loop of search terms
    Inner loop of Find to deal with duplicate entries


    But looping through cells, 60,000 rows NO

    An even cheesier way to deal with this would be to put new lines of the Product and Type at the top of the page so that any other VLOOKUPS in the sheet would catch those and miss the bad info below.

  6. #6
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Looping 'find' to find a value and replace a value in an adjacent column

    I meant NO coding, and just manual filter 15 times to keep it simple.

    Looping through 60,000 cells ONCE is not that big of a deal, although it is NOT optimal. Arrays when you don't understand them are worse than looping 60k times, as silly as that seems.

    Yeah I think the VLOOKUP method is likely the easiest. Filter on all 15 at once, then apply the vlookup to a premade reference table. Copy and paste values then never think about it again.

    Another simple option is to create ONE lookup table where you map EVERYTHING and replace the entire problematic column with the simple vlookup. You will know it is all fixed and you can even have the formula error out when something new comes in so you can add it to the table.
    Last edited by mikeTRON; 09-12-2016 at 06:59 PM.

+ 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. Looping with find and replace
    By Monkihunta in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-23-2015, 04:50 PM
  2. looping Find and Replace over two columns
    By Monkihunta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-21-2015, 04:52 PM
  3. Replies: 3
    Last Post: 11-25-2014, 06:08 AM
  4. Find and replace with adjacent cell value.
    By james252 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-12-2014, 03:56 AM
  5. Macro to find all specific values in column and replace adjacent cell values
    By dblock02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2013, 06:03 AM
  6. Find multiple words and replace the adjacent column with one word
    By ic3cold in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-13-2011, 05:04 PM
  7. Find, Replace with and then replace adjacent cell
    By Craig2097 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2009, 12:42 PM

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