+ Reply to Thread
Results 1 to 7 of 7

Convert formula into VBA code

  1. #1
    Forum Contributor
    Join Date
    07-22-2008
    Location
    canada
    Posts
    123

    Convert formula into VBA code

    My B9:B40000 in Sheet1 contain the below formula. I have noticed slowness in excel when it starts the calculation. Is there a way to convert them into vba code?
    Please help. Thank you.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Convert formula into VBA code

    Hi,

    This really shouldn't cause a noticable slow down of your sheet.

    Do you have many volatile functions or array functions in your sheet as well?


    Also, you could make the formula slightly less complex like this:

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor
    Join Date
    07-28-2009
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    115

    Re: Convert formula into VBA code

    post your workbook...

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Convert formula into VBA code

    you could probably drop the a9="" as well as that would give n/a if blank anyway
    =IF(ISERROR(MATCH(A9,Sheet2!$A$2:Sheet2!$A$40000,0)),"",INDEX(Sheet2!$B$2:Sheet2!$B$40000,MATCH(A9,Sheet2!$A$2:Sheet2!$A$40000,0)))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Convert formula into VBA code

    hi,

    Yes, they can be converted to VBA, but I've got a couple of suggestions first...

    To halve the number of calculations, change your formulae to:
    cell B9
    Please Login or Register  to view this content.
    cell C9
    Please Login or Register  to view this content.
    Or (if I have understood correctly?) you could use
    cell B9 =
    Please Login or Register  to view this content.
    Do your formulae really need to go down to row 40,000?
    - The fewer rows you need to use the easier on Excel. You could use a "dynamic named range" (run a search for this) to cover the data range shrinking or expanding.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  6. #6
    Forum Contributor
    Join Date
    07-22-2008
    Location
    canada
    Posts
    123

    Re: Convert formula into VBA code

    Thanks for your time and suggestions. I did try them but it still slowing the excel performance. Although I am on cell 13,000 yet.

    Yes, the formula would even go down to 60,000.

    Note: there are also cells that contain small formulas that I think I would not be necessary to mention here as my main concern is this big formula.


    Please help. Thank you.

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Convert formula into VBA code

    hi,

    What version of Excel are you using?
    How many other files do you have open?
    Are you filtering the sheet too?
    Is it only slow to calculate initially, or repeatedly?
    (this is likely due to the limits of Excel's calculation dependency tree which will only allow so many formulae before it rebuilds the calculation tree at every calculation.)
    You may find some useful info on Dave &/or Charles' sites:
    www.mvps.org/dmcritchie/excel/excel.htm
    http://decisionmodels.com/calcsecrets.htm
    http://decisionmodels.com/optspeedb.htm

    I strongly recommending only copying the formula down for as many rows as is currently necessary & if the data will remain static, I recommend copying & paste special'ing as values once the calculation is complete.

    Are you aware that any macro approach is likely to be a "one off" ie the same as copying & paste special'ing?

    I'm sorry I'm off to bed now & don't have time to write a test macro at the moment. You could record a macro as you complete the steps manually & this will give us a base code to modify for you...
    If you still want a macro approach after reading Charles' site, can you please post a sample workbook as Garretonufer requested (& include your recorded code)?

    hth
    Rob
    Last edited by broro183; 09-30-2009 at 06:06 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