+ Reply to Thread
Results 1 to 12 of 12

code running to slow and to long

  1. #1
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    code running to slow and to long

    hi guys
    i have the following code
    Please Login or Register  to view this content.
    my issue is that the when i run the code it take it too long to be completed , and more then once it cause the workbook to stop working ans shut off excel , no idea why, is that because the size of the range D9:R6000 that the code need to verify or what ?? is there any way to improve that code so it will not take it so long to run ?

  2. #2
    Forum Contributor
    Join Date
    02-12-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    275

    Re: code running to slow and to long

    yes the fact that yo are looking at 15 x 6000 = 90 000 cells will slow any pc down

    try adding
    Please Login or Register  to view this content.
    where "nextcell" is a lable bust before the next line
    Please Login or Register  to view this content.

    this will give a shortcut on blank cells
    Last edited by evertjvr; 08-02-2015 at 06:10 AM. Reason: Correction

  3. #3
    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: code running to slow and to long

    Hi,

    Is this something you want to repeat on many occasions? If not why not just autofilter the data for first percentages and then NOT percentages and either manually format the cells or use a macro that looks at .SpecialCells(xlCellTypeVisible) and formats the whole filtered block for you.
    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.

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

    Re: code running to slow and to long

    Try it like this and see if this makes any difference......
    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.

  5. #5
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: code running to slow and to long

    Add this line
    Please Login or Register  to view this content.
    after
    Please Login or Register  to view this content.
    This will restrict data selection to non blank cells..

    Also do not format cell at each iteration, try to collect cell ranges to array of range & then format it in one go..

    Cheers!!

  6. #6
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    hi evertjvr than you for your suggestion, my first question is where in the code i should place the "if cell = "" then goto nextcell" ? secendly i putt the next cell just before next but i got the message sub or function not defined, ay idea what to do ????

  7. #7
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    hi sktneer
    thank you for your help , when i run your code i get run-tie error 13 type mismatch on the following line- " If IsNumeric(cell.Value) And cell <> "" Then" any idea how to resolve that matter now the code take 10 seconds until i get the debug message

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

    Re: code running to slow and to long

    If your code was running without an error before making these changes, it shouldn't produce any error with the changes applied because the only line was added in the For loop is cell<>"", otherwise all is same as your original code.

    Try changing few lines of your code to this......
    Please Login or Register  to view this content.
    And once you get an error see the status bar to know the address of the problem cell on which the code is working currently.

  9. #9
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    Hi Richard no it is only one time that i need to do when i open the work sheet and select the curacy i need to work with, sorry didn't understood your suggestion can you be more explanatory sorry not so good with VBA

  10. #10
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    ok let me try it and see do you want me to send you a sample of my file so you will understand what i am looking to do maybe you can come up with improved code ?

  11. #11
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    hi excelliot

    i tried what you said but it take it too long first i get excel no responding and it does not run the macro what is wired for me when i run the code only in the range of 1000 cells it run fast and good (ie range(D2:R1000) don't understand why
    Last edited by Pilot5000; 08-03-2015 at 05:35 AM.

  12. #12
    Registered User
    Join Date
    05-28-2013
    Location
    canada
    MS-Off Ver
    Excel 2007
    Posts
    96

    Re: code running to slow and to long

    i have done what you wore but still get the same run time error on the same line, but now i saw the problems , the reason it get the error message is because in same cell i have #value and not a number , the reason is in one cell i have number , and in the other cell i have Text "No Activity that Year" and the third cell is the sum of the other two cells , any idea how to resolve that ??????
    Last edited by Pilot5000; 08-03-2015 at 06:11 AM.

+ 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. Slow running Code
    By Ausadian in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2015, 04:41 PM
  2. Clunky Slow Code, Hides Empty Rows, Takes too long...
    By BoSonic in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-18-2013, 08:56 PM
  3. Slow running code
    By phil2006 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-13-2013, 08:02 AM
  4. vba code running too slow
    By hitsujicute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2013, 06:00 PM
  5. VBA Code running very slow. Need help
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2013, 02:13 PM
  6. Slow running code
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2008, 12:49 PM
  7. Code running slow
    By lou031205 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 12:20 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