+ Reply to Thread
Results 1 to 7 of 7

Named Range Resizing takes a long time

Hybrid View

Dafe Named Range Resizing takes a... 03-01-2013, 11:54 AM
Norie Re: Named Range Resizing... 03-01-2013, 12:03 PM
Dafe Re: Named Range Resizing... 03-01-2013, 12:41 PM
nilem Re: Named Range Resizing... 03-01-2013, 01:00 PM
Dafe Re: Named Range Resizing... 03-01-2013, 01:51 PM
Norie Re: Named Range Resizing... 03-01-2013, 01:58 PM
Dafe Re: Named Range Resizing... 03-01-2013, 02:21 PM
  1. #1
    Registered User
    Join Date
    03-01-2013
    Location
    Millbrook, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Named Range Resizing takes a long time

    Hi. I'm totally new here, but have used this forum in the past to help answer numerous questions. I've got an interesting problem that I'm hoping someone can help me with.

    I've developed a rather large macro driven Excel tool and am now at the point where I'm trying to optimize some of my somewhat poorly written code. While time-testing one of my macros, I noticed that this particular line of code is particularly time consuming. It takes 2.5 s on my computer just to run this single line. If I remove the "+ 1" from the r.Rows.Count then the time drops to 0.05 s. Is this a really inefficient way of adding a row to a named range? Can anyone suggest a faster way to accomplish the same thing?

    PHP Code: 
    Names("DevelopmentPlan").RefersTo "=" r.Resize(r.Rows.Count 1r.Columns.Count).Address 

    Where, r = Range("DevelopmentPlan")
    Last edited by Dafe; 03-01-2013 at 12:34 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Named Range Resizing takes a long time

    How large is the original range?

    I there a lot of formatting or formulas in it?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-01-2013
    Location
    Millbrook, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Named Range Resizing takes a long time

    It's not particularly big. Maybe 10 rows and 5 columns. It is formatted though - the code is actually used in a macro that allows the user to add a row to the table while still preserving the formatting and formulas.

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Named Range Resizing takes a long time

    maybe so
    With Range("DevelopmentPlan")
        .Resize(.Rows.Count + 1).Name = "DevelopmentPlan"
    End With
    for example
    Sub ert()
    With Range("DevelopmentPlan")
        .Resize(.Rows.Count + 1).Name = "DevelopmentPlan"
    End With
    With ActiveWorkbook.Names("DevelopmentPlan")
        .RefersToRange.Select
        MsgBox .RefersTo
    End With
    End Sub
    Last edited by nilem; 03-01-2013 at 01:02 PM.

  5. #5
    Registered User
    Join Date
    03-01-2013
    Location
    Millbrook, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Named Range Resizing takes a long time

    Nilem, I tried your code and it seemed to take about the same amount of time. It is a much cleaner way of writing it though, thank you for that.

    Perhaps the code isn't the problem. Maybe instead it's the repercussions of the change. I do have several large data tables that reference the named range "Development Plan". I have the spreadsheet set to manual calculation while the macro runs, but perhaps that's not enough. I guess my understanding of Excel is not great enough to understand the full impact of some of these changes.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Named Range Resizing takes a long time

    You could try turning off screen updating and setting calculation to manual in the code.
    Application.ScreenUpdating = False
    
    Application.Calculation = xlCalculationManual
    
    ' code to resize range
    
    Application.ScreenUpdating = True
    
    Application.Calculation = xlCalculationAutomatic

  7. #7
    Registered User
    Join Date
    03-01-2013
    Location
    Millbrook, Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Named Range Resizing takes a long time

    Thanks Norie. I already had both of those turned off.

    I was just doing some more experimenting and discovered that the lag exists even when I manually rename the range from within Excel. When I go to Formulas > Name Manager and resize the range, I get about a 2-3 second delay while Excel grinds away making the change. This does not happen with most of my other named ranges, so it must have to do with the 1000+ cells that are referencing this range elsewhere in the tool. Presumably they must still have to update - even with the spreadsheet set to calculate manually.

    It sounds like I should be looking to those cells for a better way to calculate/reference, rather than the macro - which seems to be fine.

    Thanks for your help, everyone. I'll report back with any new findings.

+ 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