+ Reply to Thread
Results 1 to 15 of 15

Need a fast way to do large number of replace all operations

  1. #1
    Registered User
    Join Date
    02-11-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    5

    Need a fast way to do large number of replace all operations

    I need to make systematic changes to all occurrences of large numbers of string values in large spreadsheets - along the lines of

    If value is 123Foo modified value is 123Foobar
    replace all values of 123Foo with 123Foobar
    else
    end if

    real changes are a little more complex than that and the change depends on the original value.

    The problem is that I need to be able to select a column/columns of tens of thousands of rows from a table change each value and then apply that change to every occurrence of that value in sheets of up to 500k rows and 50 columns split into various tables - and the layout and column headings aren't consistent enough to allow me to target specific regions so I need to check the whole sheet. Using the built in replace all function takes about 1.6 seconds per value so doing a whole sheet would take hours as it's searching through large amounts of data thousands of times.

    I already have code written that will loop through a selected column and make the required changes rapidly and have already tried turning off screen updating, events et.c.

    Any ideas for reducing the number of searches being done or massively speeding them up?

  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
    49,025

    Re: Need a fast way to do large number of replace all operations

    Maybe dump one or more columns into an array, process the elements in the array, and dump it back where you found it.
    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-11-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    5

    Re: Need a fast way to do large number of replace all operations

    considered that but was looking for other options as the overhead of setting up and rediming arrays might stack up quickly.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a fast way to do large number of replace all operations

    Have you tried something like this:

    Please Login or Register  to view this content.
    Last edited by xladept; 02-11-2018 at 04:46 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Need a fast way to do large number of replace all operations

    well you can give it a go and see. Maybe doing sections at a time if necessary.

    However I do wonder if you want to use something other than excel... 500,000 * 50 would be pretty big for excel even if you weren't doing anything else, let alone what you seem to be trying to do here.
    Maybe you could save as a text file (or similar), edit with something fast like sed, PowerGrep or "Find And Replace Text", then open it in excel again.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  6. #6
    Registered User
    Join Date
    02-11-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    5

    Re: Need a fast way to do large number of replace all operations

    I know there's other tools out there that would do this better unfortunately I'm limited to whats installed on the machine.

  7. #7
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Need a fast way to do large number of replace all operations

    "the layout and column headings aren't consistent enough to allow me to target specific regions so I need to check the whole sheet."

    By the way - I expect this isn't true. You can probably use whatever rules do exist regarding how the sheet is laid out to find some specific thing in each table then find the used range of that table. We would have to see the sheet to know if that works or how much time it would save.

  8. #8
    Registered User
    Join Date
    02-11-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    5

    Re: Need a fast way to do large number of replace all operations

    Have done that previously and it's worked but there's multiple (20+) different sheet layouts I have to deal with any of which are subject to change at any time so it's would mean regularly updating the specific ranges and I'm not always going to be available to do that.

  9. #9
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Need a fast way to do large number of replace all operations

    No not specific ranges.
    I am thinking (just as an example) that there are a series of words that at least one of them is in all of the tables once (maybe a sample of the column headers).
    If so you can

    search the sheet for those items
    find all the used ranges for those cells
    from this list remove duplicate ranges if they exist (now you have all the ranges)
    make the data arrays
    process then
    put them back in the sheet

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a fast way to do large number of replace all operations

    Have you looked at post #4??? It might work!

    Here's a version for all the sheets in a book:

    Please Login or Register  to view this content.
    Last edited by xladept; 02-11-2018 at 06:31 PM.

  11. #11
    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
    49,025

    Re: Need a fast way to do large number of replace all operations

    considered that but was looking for other options as the overhead of setting up and rediming arrays might stack up quickly.
    See post #4 from xlAdept .... no setting up required.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Need a fast way to do large number of replace all operations

    @ Trevor - Thanks

  13. #13
    Registered User
    Join Date
    02-11-2018
    Location
    England
    MS-Off Ver
    2016
    Posts
    5

    Re: Need a fast way to do large number of replace all operations

    Found partial solution

    dump selection into array
    Make array 1 dimension
    convert to collection using error-resume to reduce to unique values
    create dictionary of original values and modified values
    loop over all cells in used range testing if value exists in dictionary and if so replacing

    now replacing at 6500 cells/second which is lot better than 1.6 seconds per replacement

  14. #14
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,347

    Re: Need a fast way to do large number of replace all operations

    What happened when you tried Xladept's code?
    It would be polite to address that post.

  15. #15
    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
    49,025

    Re: Need a fast way to do large number of replace all operations

    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.

+ 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] Fast find and replace on a large range
    By simone77 in forum Excel General
    Replies: 9
    Last Post: 03-11-2016, 04:51 AM
  2. [SOLVED] Detecting successful replace or searching a large sheet fast
    By Tsjallie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-13-2014, 05:44 PM
  3. Fast switching between large number of worksheets
    By dilipandey in forum Excel Tips
    Replies: 0
    Last Post: 07-20-2012, 01:31 AM
  4. how to fast replace
    By simone77 in forum Excel General
    Replies: 2
    Last Post: 03-27-2012, 12:12 PM
  5. Fast character replace ?
    By Pengo3005 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 01-08-2007, 10:51 AM
  6. out of memory problem! what to do for large matrix operations?
    By MCM in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2006, 09:15 AM
  7. Fast export large 2-dim array to worksheet
    By aafraga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2006, 11:00 AM

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