+ Reply to Thread
Results 1 to 7 of 7

Optimize code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Optimize code

    Hello,
    I have this code
    Sub blabla
    pocet = Range("B" & Rows.Count).End(xlUp).Row
        For i = 1 To pocet Step 3
            Range("A" & i & ":B" & i).Cut
            ii = i + 1
            Range("F" & ii).Select
            ActiveSheet.Paste
            iii = i + 2
            Range("B" & iii).Cut
            Range("B" & ii).Select
            ActiveSheet.Paste
        Next
    End Sub
    it works, but it's really slow ... I have more than 1000 rows and this code is really really slow ... it is possible to change it and macro will be faster? thanks for any help !
    Last edited by miso.dca; 02-08-2011 at 03:36 PM.

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: how to optimalize code?

    For starters you can try and put

    Application.ScreenUpdating = False
    at the beginning of the sub

    and at the end

    Application.ScreenUpdating = True
    Also, you do not need to select an object to work with it

    Not tested but you might be able to change it all to

    Sub blabla()
    pocet = Range("B" & Rows.Count).End(xlUp).Row
        Application.ScreenUpdating = False
        For i = 1 To pocet Step 3
            Range("A" & i & ":B" & i).Cut Range("F" & i + 1).Paste
            Range("B" & i + 2).Cut Range("B" & ii)
        Next
        Application.ScreenUpdating = True
    End Sub
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: how to optimalize code?

    thank you jeffrey
    I have disabled screen updating - it is faster of course, but this :
    Range("A" & i & ":B" & i).Cut Range("F" & i + 1).Paste
    doesnt work - excel writes "Object doesnt support this property or method" - what can I do to repair it?

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: how to optimalize code?

    Take off the .paste

  5. #5
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: how to optimalize code?

    it works ! even faster but still not so fast as I think it will be

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

  7. #7
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: how to optimalize code?

    thank you ! i will check it

+ 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