Consulting

Results 1 to 7 of 7

Thread: Solved: Excel 2003 - Is there a way I can speed up my AutoFill Formula for 15,000 rows?

  1. #1
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location

    Solved: Excel 2003 - Is there a way I can speed up my AutoFill Formula for 15,000 rows?

    The bit of code below takes about 6 seconds to AutoFill a formula in Column N cells for 15,000 rows. In many cases the formula is already present in most or all of the cells; I'm only running it as a fail safe for users accidentally removing the formula in a couple of random cells. Is there anything I can do to speed up this process?

    Thank you much
    [vba]Dim LastRow As Long

    LastRow = ActiveSheet.[B65536].End(xlUp).Row

    Range("N16").FormulaR1C1 = "=RC[-5]*RC[-2]+RC[-4]"

    Application.ScreenUpdating = False

    Range("N16").AutoFill Range("N16:N" & LastRow - 1)

    Application.ScreenUpdating = True[/vba]

  2. #2
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    try setting your calculations to manual.

    [VBA]Application.Calculation = xlCalculationManual[/VBA]
    Peace of mind is found in some of the strangest places.

  3. #3
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Thanks for the tip, but doing that is not making any noticeable difference.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post the workbook Frank si that we can time it?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    How about this?
    [vba]Sub AddFormula()
    Dim RowRng() As Variant
    Dim LastRow As Long
    Dim A As Long
    LastRow = ActiveSheet.[B65536].End(xlUp).Row + 1
    ReDim RowRng(1 To LastRow, 1 To 1)
    With ActiveSheet
    For A = 1 To LastRow
    RowRng(A, 1) = "=RC[-5]*RC[-2]+RC[-4]"
    Next
    .Cells(16, 14).Resize(LastRow - 16) = RowRng
    End With
    End Sub
    [/vba]David

  6. #6
    Another possibility.
    Change cell references accordingly.

    Enter your formula in A2.
    Select A2 again, but make sure that you are not in Edit Mode.
    On the left end of the formula bar you should see a box that says the address of the cell you are in (A2).
    Click in that box and type A60000.
    Hold down your Shift key as you hit Enter.
    The range A2:A60000 should be selected.
    Hit your F2 key.
    Hit Ctrl+Enter.
    This should have entered the same formula in A2:A60000. (I am assuming that for some reason you cannot just double-click on the auto-fill handle, which, of course, would be the easiest solution.)

  7. #7
    VBAX Expert
    Joined
    Sep 2010
    Posts
    604
    Location
    Sorry guys for wasting your time. I'm an idiot some times. I had forgotten that another sub was being called within the same sub that I was using AutoFill.
    * When I dissabled that, the Autofill is lightening is fast.

    For the heck of it I put a timer on a few different AutoFill pieces of code. Below are the results
    [vba]
    '15,000 Rows

    Dim LastRow As Long

    LastRow = ActiveSheet.[B65536].End(xlUp).Row

    Application.ScreenUpdating = False

    '====================================================
    'Timer result was .145
    Range("N16").FormulaR1C1 = "=RC[-5]*RC[-2]+RC[-4]"
    Range("N16").AutoFill Range("N16:N" & LastRow - 1)

    '====================================================
    'Timer result was .082
    Range("N16:N" & LastRow - 1).FormulaR1C1 = "=RC[-5]*RC[-2]+RC[-4]"

    '====================================================
    'Timer result was .176
    Dim RowRng() As Variant
    Dim A As Long

    ReDim RowRng(1 To LastRow, 1 To 1)

    With ActiveSheet
    For A = 1 To LastRow
    RowRng(A, 1) = "=RC[-5]*RC[-2]+RC[-4]"
    Next
    .Cells(16, 14).Resize(LastRow - 16) = RowRng
    End With

    Application.ScreenUpdating = True
    [/vba]
    Last edited by frank_m; 12-17-2010 at 02:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •