+ Reply to Thread
Results 1 to 11 of 11

Extracting partial red strings and replacing them with dots

  1. #1
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Extracting partial red strings and replacing them with dots

    Working on a large worksheet with 80k or rows and 8 columns A-H, I need to:

    1. Extract the red text from each cell in Column F,
    2. place it in the same row at column I, and
    3. fill its position with ten dots.

    I have attached an example with two worksheets, where Sheet1 has the raw data before any processing, and Sheet2 with data in its final shape. For sure, there's no need to retain the red colour in ColI as it is in the example, I put it in red just for illustration.

    Please note that the real red data in ColF vary dramatically in size, so "a special method" (?) is needed to quicken both extraction and dots replacement process.

    More than grateful for any precious assitance with this question.

    Many thanks in advance.

    T.
    Attached Files Attached Files

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Extracting partial red strings and replacing them with dots

    You may try something like this...

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Extracting partial red strings and replacing them with dots

    I really hope to be proven wrong but I think this can only be done by checking cell by cell and character by character to determine font color.

    Since you talk about 80K rows I'm afraid it's going to take forever.

    Edit:

    sktneer has provided you the method I was talking about but I'm not sure this is realistic for 80K rows.
    Last edited by bakerman2; 10-31-2019 at 02:33 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Extracting partial red strings and replacing them with dots

    Thanks Bakerman2 for your input, which I really appreciate. In fact, I tried Sktneer's script and it worked great with the following comments:

    @Sktneer, really thank you very much for your prompt solution. I tried it on 155 records (rows) of my real data and found:
    1. it did extract the red portions and placed them in ColI,
    2. it did replace the red portions in their original F column positions with dots, but actually NOT 10 DOTS, BUT LOTS AND LOTS OF DOTS, which is not the desired result,
    3. it took nearly 3 minutes to finish 155 rows.

    So, is it possible to modify the script to accommodate for a 10-dot replacement only, and to make the script run a "bit faster" as I requested in my original question?
    Once again, thank you very much Sktneer for such masterpiece code ..

  5. #5
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Extracting partial red strings and replacing them with dots

    For length of the dots, you only need to change the line...
    Cel.Value = Replace(Cel.Value, Str, WorksheetFunction.Rept(".", Len(Str)))

    To This...
    Cel.Value = Replace(Cel.Value, Str, WorksheetFunction.Rept(".", 10))

    You need to be patient while running this code on a large data set. For 80000 rows, it should take approx. 10 minutes to complete.

  6. #6
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Extracting partial red strings and replacing them with dots

    Thank you very much Sktneer for your prompt and valuable response.
    I did apply the change, and it worked perfectly.
    This question is solved by you Sktneer through your genius code.
    Please accept my deep respect and gratitude.

    All the best ..

    T.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Extracting partial red strings and replacing them with dots

    You're welcome T! Glad it worked as desired.
    Thanks for the rep and feedback!

    sktneer

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Extracting partial red strings and replacing them with dots

    FWIW, it shoudl be faster if you use arrays rather than modifying cell by cell:

    Please Login or Register  to view this content.
    Rory

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Extracting partial red strings and replacing them with dots

    Out of curiousity I ran both codes on 80K rows.

    Rory's code took approx. 16 minutes.

    sktneer's code took approx. 30 minutes.

    Hopefully it's just a 1 time thing that needs to be run.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Extracting partial red strings and replacing them with dots

    Were you very bored?

  11. #11
    Forum Contributor
    Join Date
    04-04-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    204

    Re: Extracting partial red strings and replacing them with dots

    Quote Originally Posted by rorya View Post
    Were you very bored?
    I'm very sorry rorya for this belated reply, I just noticed it as I'm back to work.
    I really don't know what to say, thank you very much indeed for such masterpiece code. It did run far much faster saving a lot of time.
    .. with full respect and gratitude.

    All the best.

    T.

+ 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] Particualr sorting of data groups and replacing red text with ten dots
    By terryhenderson in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-04-2019, 02:55 AM
  2. Replacing partial formulas
    By Neil_wylie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2017, 06:06 AM
  3. Replacing dots using VBA
    By Graga in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-28-2015, 08:49 AM
  4. Replacing strings/ replacing numbers and letters
    By Insert Name in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2015, 01:15 PM
  5. Replacing comma with nothing replaces both dots and commas??
    By rthell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-03-2014, 07:38 AM
  6. Replacing whole cell with a partial string criterica
    By skyt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-31-2010, 04:03 PM
  7. Replacing dots with commas using macro
    By maxest in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-06-2006, 11:35 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