+ Reply to Thread
Results 1 to 4 of 4

Excel 2010 and checkbox : very slow ?

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    2

    Excel 2010 and checkbox : very slow ?

    Hi

    I wrote some times ago a macro that add checkboxes in a sheet (I found some part on the net)
    On Office 2003 and 2007, no trouble at all. But in office 2010, the same macro is now very slow
    here is an example that add a checkbox on 800 rows
    Sub Macro1()
    Dim l2, i As Integer
    Dim r As Range
    Dim Data As Range
    Dim dtmTest As Date
    Dim dtmTest2 As Date
    
      
        l2 = 800
            
        dtmTest = TimeValue(Now)
        
        i = 0
        Set Data = Range("F3:F" & l2)
        For Each r In Data
            i = i + 1
            Set Cbox = ActiveSheet.CheckBoxes.Add(r.Left + 4, r.Top, r.Width, r.Height)
            With Cbox
               .Value = xlOn
                .LinkedCell = "$G$" & r.Row
                .Display3DShading = True
                .Caption = "ACTIF"
            End With
        Next r
        
        dtmTest2 = TimeValue(Now)
            
        MsgBox (DateDiff("s", dtmTest, dtmTest2))
    End Sub
    it takes 220 seconds to perform the macro in Excel 2010 and only 17 seconds in Excel 2007 !
    If I comment the .value, .LinkedCell and .Display3DShading lines, it only takes 12 secondes in Excel 2010 (but if one of these three lines is present in the code, the macro takes again more than 200 seconds). So it seems this part of the code has a problem ... but I'm unable to find why !

    Is there another way to quickly create checkboxes and modify their properties ?

    Regards
    Last edited by ilive; 06-12-2013 at 02:51 PM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Excel 2010 and checkbox : very slow ?

    Try this...

    Sub Macro1()
    Dim l2 As Integer, r As Range, Data As Range, dtmTest As Date, dtmTest2 As Date
    
    l2 = 800
    dtmTest = TimeValue(Now)
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
    Set Data = Range("F3:F" & l2)
    
    For Each r In Data
        With r
            Set Cbox = ActiveSheet.CheckBoxes.Add(.Left + 4, .Top, .Width, .Height)
        End With
        With Cbox
            .Value = xlOn
            .LinkedCell = "$G$" & r.Row
            .Display3DShading = True
            .Caption = "ACTIF"
        End With
    Next r
    
    dtmTest2 = TimeValue(Now)
        
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
        
    MsgBox (DateDiff("s", dtmTest, dtmTest2))
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Excel 2010 and checkbox : very slow ?

    add
      Application.ScreenUpdating = False
    before you start the loop
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    06-12-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Excel 2010 and checkbox : very slow ?

    it works ! speed of the macro is now the same as the one on Excel 2007
    thanks a lot for your answers

+ 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