+ Reply to Thread
Results 1 to 3 of 3

my macro run very slowly

  1. #1
    Registered User
    Join Date
    10-06-2011
    Location
    Edinburgh, scotand
    MS-Off Ver
    Office 365
    Posts
    3

    my macro run very slowly

    Hi, When I'm running Macro .... it take ages to save.. below is my code. suggest me how can I run my Macro faster. sumtume i have work to 488 row to 20000 rows

    Sub Sufficient()

    'Copy cells of cols A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S from rows containing "Sufficient" in
    'col M of the active worksheet (Master) to cols
    'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S of Sufficient(Sufficient)
    Dim DestSheet As Worksheet
    Set DestSheet = Worksheets("Sufficient")

    Dim sRow As Long 'row index on Master worksheet

    Dim sCount As Long
    sCount = 0
    dRow = 1



    For sRow = 1 To Range("S65536").End(xlUp).Row
    'use pattern matching to find "Sufficient" anywhere in cell


    If Cells(sRow, "S") Like "*Sufficient*" Then


    sCount = sCount + 1
    dRow = dRow + 1
    'copy cols A,B,C,D,E,F,G,H,I,J, K,L,M,N,O,P,Q,R,& S
    Cells(sRow, "A").Copy Destination:=DestSheet.Cells(dRow, "A")
    Cells(sRow, "B").Copy Destination:=DestSheet.Cells(dRow, "B")
    Cells(sRow, "C").Copy Destination:=DestSheet.Cells(dRow, "C")
    Cells(sRow, "D").Copy Destination:=DestSheet.Cells(dRow, "D")
    Cells(sRow, "E").Copy Destination:=DestSheet.Cells(dRow, "E")
    Cells(sRow, "F").Copy Destination:=DestSheet.Cells(dRow, "F")
    Cells(sRow, "G").Copy Destination:=DestSheet.Cells(dRow, "G")
    Cells(sRow, "H").Copy Destination:=DestSheet.Cells(dRow, "H")
    Cells(sRow, "I").Copy Destination:=DestSheet.Cells(dRow, "I")
    Cells(sRow, "J").Copy Destination:=DestSheet.Cells(dRow, "J")
    Cells(sRow, "K").Copy Destination:=DestSheet.Cells(dRow, "K")
    Cells(sRow, "L").Copy Destination:=DestSheet.Cells(dRow, "L")
    Cells(sRow, "M").Copy Destination:=DestSheet.Cells(dRow, "M")
    Cells(sRow, "N").Copy Destination:=DestSheet.Cells(dRow, "N")
    Cells(sRow, "O").Copy Destination:=DestSheet.Cells(dRow, "O")
    Cells(sRow, "P").Copy Destination:=DestSheet.Cells(dRow, "P")
    Cells(sRow, "Q").Copy Destination:=DestSheet.Cells(dRow, "Q")
    Cells(sRow, "R").Copy Destination:=DestSheet.Cells(dRow, "R")
    Cells(sRow, "S").Copy Destination:=DestSheet.Cells(dRow, "S")
    End If
    Next sRow

    MsgBox sCount & " Sufficient rows copied", vbInformation, "Transfer Done"



    End Sub
    Last edited by adcz250; 10-06-2011 at 02:31 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Run Macro faster

    Hi adcz250, welcome to the forum! Please take a few minutes to read our Forum Rules, then edit your post to include a more descriptive title AND add code tags to your code. Once this has been completed, we'll be happy to help you resolve your issue.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Run Macro faster

    Welcome to the forum! Please take a minute to review forum rules about how to post code so it will display properly. In the meantime, instead of looping through all of those cells, consider looking into Cells.Find - it may be faster.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

+ 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