+ Reply to Thread
Results 1 to 22 of 22

how to speed up my macro, going very slow, row by row

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    how to speed up my macro, going very slow, row by row

    i have this code that runs terribly slow. can someone help me with this?

    Please Login or Register  to view this content.
    basically i check for a white background and turn it to gray
    and then i turn black text to white. but it is very slow. is this something for cells to use?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260

    Re: how to speed up my macro, going very slow, row by row

    That is an awful lot of cells to check...
    Remember what the dormouse said
    Feed your head

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    note, im trying to use Dark Mode with office. i can successfully change everything (that's a white bg color) to a dark gray. then i need to set the font color to white if its black. if i manually select cells and change the bg color, it's very fast. same with font color. is there a way to do this fast?

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    i tried this but still the same slowness:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    so i got around the slowness by doing the following:

    Please Login or Register  to view this content.
    but when i do this, nothing happens, what am i doing wrong?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,908

    Re: how to speed up my macro, going very slow, row by row

    You don't need .Cells in front of interior color.

    You can set interior color of entire range in one shot.
    Ex:
    Please Login or Register  to view this content.
    However... do note that applying formats to unused range (i.e. range not holding values etc) could severely impact workbook performance.

    As formats will tag every cell in worksheet as used range. This is terrible practice.

    EDIT: Just tested, huh what do you know. It wasn't as bad as I had expected. Only increased size by about 1kb. And formula performance wasn't bad. Perhaps, uniform fill color & font color alone doesn't have huge impact.
    Last edited by CK76; 08-01-2019 at 11:17 AM. Reason: Grammer
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: how to speed up my macro, going very slow, row by row

    Stating the obvious but are you sure there are any cells with the colours you mention?

    Are you able to upload the workbook?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,908

    Re: how to speed up my macro, going very slow, row by row

    Oh one more thing. If you check entire range's .Cells.Interior.Color, unless it's uniform color. It will always return 0.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    thanks CK for that kernel of logic. didn't know that. so here is my code. the fill is set to gray and the statement works and is very fast (under 1 second). but now i have a problem with the font color not changing. see code below. will upload a

    Please Login or Register  to view this content.
    here is the file, just one sheet (sheet5) with code
    Attached Files Attached Files

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,908

    Re: how to speed up my macro, going very slow, row by row

    In your sample, you are using Font.ColorIndex instead of Font.Color

    As I've stated, when there is different fill color, or font color present in the sheet. It will return default value.

    So for .Interior.Color it will return 0 in your sample and .Font.Color will return Null.

    I'm not sure why you are checking entire range's property for each. It really gives you no control over individual cell's format.

    Personally... I'd just set the entire sheet as desired. Then apply any other formats later.

    Ex:
    Please Login or Register  to view this content.
    FYI to check for null value, you'd use IsNull(.Font.Color).

  11. #11
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    so some background on this macro, i have fallen in love with dark mode and i want this across all office products. that part was easy as it is done in one step. getting the body of a sheet to be the same, not so easy. i want a QAT button to turn on the dark mode for the sheets (and one to turn it off if i run into any difficulties). so if it is an unused sheet, then changing the fill and font color is easy. but what if i have an existing sheet that has various fills and font colors, then i would be changing the whole sheet and i don't want that. basically i want the sheet to examine the fill and font color, if a cells properties are no fill then change it to gray and if the font color is automatic, then change the font color to white.

    does that help?

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    FYI to check for null value, you'd use IsNull(.Font.Color).
    so i did this:

    Please Login or Register  to view this content.
    and it changed the font from red to white. i don't want that. if the font color is automatic (or null), then set it to white, otherwise leave it alone.

  13. #13
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,908

    Re: how to speed up my macro, going very slow, row by row

    if the font color is automatic (or null), then set it to white, otherwise leave it alone.
    This isn't possible when you do entire range in one shot. You have to iterate cell by cell. Which is very time consuming process.
    Hence, my comment that it's not a good idea to do this

    Alternative method is...
    Create new sheet. Set up entire range using code provided for fill color and font color.
    Then in original worksheet, iterate over each cell of used range and transfer format to new sheet. Once satisfied, you can delete the original.

    Ex:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    11-06-2012
    Location
    Texas
    MS-Off Ver
    O365
    Posts
    27

    Re: how to speed up my macro, going very slow, row by row

    You're changing billions of cells. 16384 Columns x 1048576 Rows. Try limiting yourself to a much smaller range.

  15. #15
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: how to speed up my macro, going very slow, row by row

    Quote Originally Posted by Daishiknyte View Post
    You're changing billions of cells. 16384 Columns x 1048576 Rows. Try limiting yourself to a much smaller range.
    ....and the UsedRange would be a good place to start....

  16. #16
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,308

    Re: how to speed up my macro, going very slow, row by row

    @dmcgov, surely the question has to be asked, why ?, as you will never see or use 99.9% of the sheet.
    torachan.

  17. #17
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    so yup, after some consideration, i will try coding just the usedrange for the font color. I will post back once i have some code to work with

  18. #18
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    so here is the code that i have (based on user comments).

    Please Login or Register  to view this content.
    what i want is for rng to be activesheet.usedrange. that part is easy.

    but for rng2 and 3, i want the unused columns and unused rows. how can that be done.

  19. #19
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,908

    Re: how to speed up my macro, going very slow, row by row

    This...
    Please Login or Register  to view this content.

  20. #20
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    Perfect, thanks CK, that did the trick.

  21. #21
    Registered User
    Join Date
    08-05-2019
    Location
    İstanbul Florya
    MS-Off Ver
    2016
    Posts
    4

    Re: how to speed up my macro, going very slow, row by row

    Bu sorun bende de var

  22. #22
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to speed up my macro, going very slow, row by row

    Çözüm sizin için işe yaradı mı?

+ 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. Speed up very slow Macro
    By seanpears99 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2016, 09:30 PM
  2. Macro to remove a list of Char iworks but is slow, possible to speed it up?
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-01-2013, 12:11 PM
  3. [SOLVED] How to speed up a slow responding macro
    By ROHAN999 in forum Excel Programming / VBA / Macros
    Replies: 42
    Last Post: 09-29-2013, 03:30 PM
  4. [SOLVED] Very Slow Macro... Any Advice How To Speed It Up, Please?
    By mrodrigues in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-07-2012, 04:37 PM
  5. [SOLVED] Speed up slow macro loop
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-15-2012, 11:41 AM
  6. How can I speed up this slow macro?
    By rs2k in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2008, 08:34 PM
  7. [SOLVED] slow Macro speed
    By Lam Chop in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2006, 11:10 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