+ Reply to Thread
Results 1 to 8 of 8

Ugly slow code....

Hybrid View

  1. #1
    Registered User
    Join Date
    07-15-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    51

    Exclamation Ugly slow code....

    Works, but really slow.....
          Sheets("TS1").Rows("3:3").Delete
                Sheets("TS2").Rows("3:3").Delete
                Sheets("TS3").Rows("3:3").Delete
                Sheets("TS4").Rows("3:3").Delete
                Sheets("ML13").Rows("3:3").Delete
                Sheets("ML24").Rows("3:3").Delete
                Sheets("SL13").Rows("3:3").Delete
                Sheets("SL24").Rows("3:3").Delete
                Sheets("TV1").Rows("3:3").Delete
            
                Sheets("TS1").Rows("44:44").Insert
                Sheets("TS2").Rows("44:44").Insert
                Sheets("TS3").Rows("44:44").Insert
                Sheets("TS4").Rows("44:44").Insert
                Sheets("ML13").Rows("44:44").Insert
                Sheets("ML24").Rows("44:44").Insert
                Sheets("SL13").Rows("44:44").Insert
                Sheets("SL24").Rows("44:44").Insert
                Sheets("TV1").Rows("44:44").Insert
    I tried Array it didnt work for me, Any ideas for faster cleaner code?

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Ugly slow code....

    Sub snb()
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
            .EnableEvents = False
        End With
        
        For Each sh In Sheets
            sh.Rows(3).Delete
        Next
        Sheets(1).Rows(44).Insert
        Sheets.FillAcrossSheets Sheets(1).Rows(44), xlFillWithAll
        
        With Application
            .ScreenUpdating = True
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
        End With
       
    End Sub
    Last edited by snb; 08-15-2010 at 04:26 PM.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Ugly slow code....

        Dim v As Variant
        
        Application.Calculation = xlCalculationManual
        For Each v In Array("TS1", "TS2", "TS3", "TS4", "ML13", "ML24", "SL13", "SL24", "TV1")
            Worksheets(v).Rows(3).Delete
            Worksheets(v).Rows(44).Insert
        Next v
        Application.Calculation = xlCalculationAutomatic
    Last edited by shg; 08-16-2010 at 08:16 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-15-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Ugly slow code....

    thanks, its didnt help improve .....slowness.....loooking for source......

  5. #5
    Registered User
    Join Date
    07-15-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Ugly slow code....

    The prob is $1:200 reference back to the sheets just changed.
    Even, insert/ delete should keep range intact.

    Excel slows. iguess checking everything.

    Any thoughts?

  6. #6
    Registered User
    Join Date
    07-15-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Ugly slow code....

    any other ideas?

  7. #7
    Registered User
    Join Date
    07-21-2010
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Ugly slow code....

    SlyOne2,

    When you say "slow" what time frame are talking about (10 seconds, longer?) so we can have an idea what we are trying to improve upon. Also, how many average columns and rows are there per sheet? Do you have a lot of formulas? As you see "snb" turned off the calculations to speed things up. Give us more to go on.

    Danny
    Or just an average are

  8. #8
    Registered User
    Join Date
    07-15-2010
    Location
    usa
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Ugly slow code....

    Timing:
    When I comment out /loop around my ugly or Shg code it take 25 seconds.....
    When use my ugly or Shg code it take 3-4 minutes...
    Rows start from 4 goto 200 per sheets. columns around 200 per sheets.

    The only thing different is deleting and insert rows, which seems to throw Hlookup into tizzy.
    The sheets are tables, since old rows in tables are not used, I want to delete to keep xls small.

    Hlookup use $1:$200 to find row.
    Last edited by Slyone2; 08-16-2010 at 08:23 PM.

+ 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