+ Reply to Thread
Results 1 to 8 of 8

Macro take 40 secound to run

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-02-2010
    Location
    singapore
    MS-Off Ver
    MS365
    Posts
    287

    Macro take 40 secound to run

    Hi All,

    Sorry for a super long coding. As I record manually without any editing.
    Therefore, I look forward for your help.
    This coding take about 40 secound to run. Its really take too long.
    Is it able to edit it to be more faster?

    For your info, I will using the same coding to edit into difference customer.

    Due to the code more then 10,000 characters long, therefore I paste it into txt file.

    Best Regards
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Macro take 40 secound to run

    Hello Cyee:
    I don't think to many people are going to read all that code ... however if you start a post that tells people eactly what your goal is I'm would think you will get help on creating the code.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro take 40 secound to run

    Hmm?

    You can get rid of all the lines like
    ActiveWindow.ScrollRow = ##
    Then get rid of Select
    eg
        Columns("B:E").Select
        Selection.Delete Shift:=xlToLeft
    becomes
        Columns("B:E").Delete Shift:=xlToLeft
    Similarly with .Activate

    You should record your macros in smaller chunks then add them together

    Select really drags code down and is very seldom needed.

    By working in smaller chunks you could possibly aviod scrolling altogether.

    Remember that the Macro Recorder cannot predict what you want next so it records nearly everything you do, including selecting cells until you decide what next to do.

    Your code will take a fair bit of time to clean out.
    Can you supply a workbook to work with?

    It should not contain any sensitive data
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,303

    Re: Macro take 40 secound to run

    Hi cyee,

    I've trimmed out a lot of useless stuff from your text file. Here is what I suggest.
    Do your process a few times by hand so you knew exactly the keystrokes and things you need. After you have it to a minimum, then record your macro. This alone should make yoiur macro about half as long.

    For example you have Selected columns C and then deleted it. You did it again to column D. You should have selected BOTH columns and then deleted them. This would make for a smaller and better macro. The same is true for AutoFit for columns. Instead of doing them separaely, select all of them and do it all at once.

    Next....

    Whenever you see stuff like
    Columns("J:J").Select
    Selection.Cut
    You can make this a single line with:
    Columns("J:J").Cut
    Also - you need to learn to SET BREAKPOINTS and STEP through your macro to see what is useless steps and delete them. Read - http://www.cpearson.com/excel/Debug.htm

    Find the attached with a lot of useless lines gone.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Contributor
    Join Date
    09-02-2010
    Location
    singapore
    MS-Off Ver
    MS365
    Posts
    287

    Re: Macro take 40 secound to run

    Thanks all for the help.

    I able to sort a bit faster now :p

    BTW, I hereby attached the result in excel file. There is alot of blank rows.
    May I know how to auto delete all the blank rows?
    Attached Files Attached Files

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,303

    Re: Macro take 40 secound to run

    Hi,
    You should start a new question / thread with this last problem.

  7. #7
    Forum Contributor
    Join Date
    09-02-2010
    Location
    singapore
    MS-Off Ver
    MS365
    Posts
    287

    Delete Blank Rows

    I hereby attached the result in excel file. There is alot of blank rows.
    May I know how to auto delete all the blank rows?
    Attached Files Attached Files

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,303

    Re: Delete Blank Rows

    Hi Charlene,

    This code will delete those blank rows on your sheet. Set a breakpoint in it and step through it to see what it is doing.
    Sub DeleteBlankRows()
    
        Dim RowAboveGrandTot As Double
        Dim LastRowOfData As Double
        
        RowAboveGrandTot = Cells(Rows.Count, "A").End(xlUp).Row - 1
        LastRowOfData = Cells(RowAboveGrandTot, "A").End(xlUp).Row + 1
        Rows(LastRowOfData & ":" & RowAboveGrandTot).Delete shift:=xlUp
        
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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