+ Reply to Thread
Results 1 to 7 of 7

How can I speed up this slow macro?

  1. #1
    Registered User
    Join Date
    07-17-2008
    Location
    Kansas, USA
    Posts
    3

    How can I speed up this slow macro?

    I have a 17,000 row excel 2007 spread sheet that looks like this:

    PHP Code: 
       A         B      C       D         E         F         G        H
    DATA    2000    2003    Isuzu    Trooper     DATA    DATA    DATA
    DATA    1996    1999    Isuzu    Oasis       DATA    DATA    DATA
    DATA    2003    2004    Isuzu    Ascender    DATA    DATA    DATA 

    I want it to look more like this:

    PHP Code: 
       A         B      C       D         E         F         G        H
    DATA    2000            Isuzu    Trooper     DATA    DATA    DATA
    DATA    2001            Isuzu    Trooper     DATA    DATA    DATA
    DATA    2002            Isuzu    Trooper     DATA    DATA    DATA
    DATA    2003            Isuzu    Trooper     DATA    DATA    DATA
    DATA    1996            Isuzu    Oasis       DATA    DATA    DATA
    DATA    1997            Isuzu    Oasis       DATA    DATA    DATA
    DATA    1998            Isuzu    Oasis       DATA    DATA    DATA
    DATA    1999            Isuzu    Oasis       DATA    DATA    DATA
    DATA    2003            Isuzu    Ascender    DATA    DATA    DATA
    DATA    2004            Isuzu    Ascender    DATA    DATA    DATA 
    PHP Code: 
    Here is the macro I created to do this:

    Dim year1 As Integer
    Dim year2 
    As Integer
    Dim counter 
    As Integer
    Range
    ("B1").Select

    Do While Not IsEmpty(ActiveCell)

    ActiveCell.Offset(10).Select
    year1 
    ActiveCell.Value
    year2 
    ActiveCell.Offset(01).Value
    counter 
    year2 year1
    ActiveCell
    .Offset(01).Value ""

    Do While counter 0
    ActiveCell
    .EntireRow.Select
    Application
    .CutCopyMode False
    Selection
    .Copy
    ActiveCell
    .Offset(10).Select
    ActiveCell
    .EntireRow.Select
    Selection
    .Insert Shift:=xlDown
    ActiveCell
    .Offset(01).Select
    ActiveCell
    .Value ActiveCell.Value 1
    counter 
    counter 1
    Loop

    Loop
    End Sub 

    The problem is that after the first 100 or so lines the macro slows down to 1 line every 1 second. After 400 lines is slows to 1 line every 2 seconds. I am guessing that I will have around 300,000 lines after everything is said and done. At the rate this thing is running it will take a year to finish. Is there a better way to acomplish what I need?

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    See if this is any faster.

    Please Login or Register  to view this content.
    rylo

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-17-2008
    Location
    Kansas, USA
    Posts
    3
    Quote Originally Posted by rylo
    Hi

    See if this is any faster.

    Please Login or Register  to view this content.
    rylo

    Thank you,

    I tried this out and got the following error:

    Run-time error '1004':

    Application-defined or object-defined error.

    Any ideas?

  5. #5
    Registered User
    Join Date
    07-17-2008
    Location
    Kansas, USA
    Posts
    3
    Quote Originally Posted by jindon
    Please Login or Register  to view this content.

    Thank you,

    I tried this one out and received the following error:

    Run-time error '7':

    Out of memory


    If it makes any difference I running this on a dual XEON machine with 2 GB of RAM with 32 bit XP.

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    I put your example data into the range A1:H3, then copied it down until row 10000.

    Ran my code, and it didn't give any errors, and completed in about 1 min.

    How about you put up an example workbook, with data that causes an error. Make sure it is in 2003 format, not 2007

    rylo

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524
    try
    It should finish within a second.
    Please Login or Register  to view this content.

+ 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