+ Reply to Thread
Results 1 to 13 of 13

Using a macro in place of formulae?

  1. #1
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Using a macro in place of formulae?

    Hello,

    Firstly many thanks for taking a look at my post, my current problem is i deal with huge huge datsets, consisting of more than 8million cells. I have come to find that putting equations containing alot of if/or/and/isnumber functions, makes excel grind to a virtual hault. Just clicking on a cell taks 30 seconds! A friend has told me i should start making macros to perform the calculations as oppose to having thousands of formulae. I was wondering if someone could provide me with a macro to perform the functions of the following equation. Hopefully this will provide me with the ability/template, to create more macros like it in order to perform the functions that I desire.

    Again many thanks for looking,

    All the best

    Alan
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Using a macro in place of formulae?

    Hi Alan,
    It is my understanding that Excel's native formulas are optimized to be as fast as possible. If you create User Defined Functions (UDF's) and make them Volitile, that will slow things down even more.
    DonkeyOte has a link to why things slow down at http://www.decisionmodels.com/calcsecretsi.htm

    My suggestion is to make Calculation Manual and enter all your numbers and only calculate when you press the F9 Key.

    I deal with some large data sets and find Pivot Tables are the fastest way to get results, but your data is formatted nicely for Pivots.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Using a macro in place of formulae?

    This is very interesting, and am now using the following macro to stop automatic recalculation

    Please Login or Register  to view this content.
    However i still have the need to have macros performing calculations for other reasons, including recogntion of user defined cell formatting. The information you supplied was however useful, ill boost your reputation as such!

    Many thanks

    Alan

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Using a macro in place of formulae?

    If you don't want/need to recalculate the entire workbook and are only interested in a certain row or column you can use code like:

    Turn calculation off with your xlManual above and then
    Range("A1:A30").Calculate for a set range
    or
    Rows(10).Calculate for a single row
    or
    Columns("F").Calculate

    The above range calculate examples may save lots of time if you can use them.
    see http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
    or Range.Calculate on http://msdn.microsoft.com/en-us/library/bb687891.aspx

  5. #5
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Using a macro in place of formulae?

    Again this is very interesting. But i do still need a way of performing very simple calculations via a macro as oppose to in the sheet. User defined conditional formatting is one reason. But also for when i alow other members of staff to access without knowing the equation that defines the cell. (For personal security reasons)

    Any help on this would be greatly appreciated.

    All the best

    Alan

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Using a macro in place of formulae?

    Hi Alan,

    Find the attached with 3 simple User Defined Functions (UDF). The way each one works is this.
    1. In a cell , type an equal sign and then the name of the UDF name. ie "=SumByName"
    2. These UDF need an argument of the name you want so you need to add a name ie "=SumByName("mary")
    3. You can also put a cell that points to a name ie "=SumByName(A18)"

    Using Application.Volitile will make these UDF recalculate whenever there is a change to your worksheet. If you thought things were slow before, see how much slower after using a bunch of these volitile functions.

    I have set the range of where the sum, count and average are performed using a varialbe of MaxColumn and set it to 11 as per your example. You will need to change this (and also the 2) as your data moves.

    The last part is, every function needs to return their calculations to the spreadsheet. You do this by using the UDF name in the code.

    Here is what you wanted, but I'm not sure it really is.
    Attached Files Attached Files

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Using a macro in place of formulae?

    Hi Alan
    I might be mistaken but, from reading your posts, I believe you're looking for something more like this
    Please Login or Register  to view this content.
    If not, throw it away. The code is based on your sample file.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Using a macro in place of formulae?

    reputation boosted! This will give me the template i require!

    Many thanks!

    Alan

  9. #9
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Using a macro in place of formulae?

    Again thanks for the help just to prove this template has helped me form a template, and improve my understanding, i used it to achieve the results of colomn "O" i.e. the average, without needing the countif and sum listed on the sheet.

    Many thanks again

    Alan
    Please Login or Register  to view this content.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Using a macro in place of formulae?

    Nice Alan.

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

    Re: Using a macro in place of formulae?

    Excel will be faster if

    - you do the calculations in memory (arrays)
    - if you reduce the number of writing operations:

    Please Login or Register  to view this content.



  12. #12
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Using a macro in place of formulae?

    Hello SNB i like the idea of making it faster, however i cannot get this code to work, any chance of sticking it in the document in a format that works? Or breaking it down so i understand the code and can edit it a bit better.

    Many thanks

    Alan

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

    Re: Using a macro in place of formulae?

    I improved the code to:

    Please Login or Register  to view this content.
    and implemented it in the attachment.
    Attached Files Attached Files

+ 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