+ Reply to Thread
Results 1 to 15 of 15

auto calculating formula or macro, not sure.

  1. #1
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    auto calculating formula or macro, not sure.

    Looking for a =SUM or =Vlookup or other formula/macro that can average 15 minutes of data based upon a THEORITICAL VALUE. Ideally, I would like to have the THEORITICAL VALUE in the formula and not reference a cell. I tried fooling around combining nested =countifs() formulas from other threads but failed.
    The attached file provides a more descriptive explanation. Thanks in advance. MP

    I've been fooling around with Solver for this but not sure if that works. Also the above file did not have the solver loaded into it when I uploaded it.
    Attached Files Attached Files
    Last edited by Mechanical Pencil; 10-27-2013 at 07:41 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: auto calculating formula or macro, not sure.

    See the attached Excel 2003 file (which is a copy of your file with additions) that
    contains Macros that should get you started. I don't think it does exactly what you want,
    since it hard codes the 'start cell' and the 'theoretical value' for each of the three calculations.

    The Macros are included here:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by LJMetzger; 10-27-2013 at 05:05 PM. Reason: Corrected typo '20#' was '80#' after 'First Calculation'

  3. #3
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    Re: auto calculating formula or macro, not sure.

    Its a start and I will fool around with it and report back. I'm getting better with VBA. Thanks a bunch.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: auto calculating formula or macro, not sure.

    Hi Metzger

    Most impressive macro! Found a small glich in row below "First Calculation"

    Please Login or Register  to view this content.
    should be 20 of cource.

    Alf

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: auto calculating formula or macro, not sure.

    Maybe Im missing something, but where does the "theoretical value" come in with this? In your sample workbook you have...
    =AVERAGE(B32:B46) TV = 20
    =AVERAGE(B65:B79) TV = 0
    =AVERAGE(B117:B131) TV = 85

    I dont get how you are using the 20, 0, 85???
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: auto calculating formula or macro, not sure.

    Alf,

    Thanks for catching my error. If you need statistics, it's relatively easy to add standard deviation, and to search for outlier values (outside of +/- 2 standard deviations, or +/- 3 standard deviations, etc.).

    Lewis

  7. #7
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    Re: auto calculating formula or macro, not sure.

    I get this every day. The times are never exact, it is always plus/minus a few minutes from the start. I have to average out the data every time by adjusting the formula.

    I'm looking for a formula or VBA code that can scan the minute data based upon a theoretical value and calculate a 15 minute average. The TV can be any value, 5, 100, 250, 450, 850. In this instance, its 20, 0 and 85.

    This is a big code and it will take me a while to figure I all out. This is way beyond me so thanks for your patience in advance. So far so good.

    I like how it calculates but is there a way to have the results populate specific cells? This is already done with the above post from LJM. My misunderstanding. I need to figure out how to change the cells it is assigned to.

    I have to run, be back in an hour.
    Last edited by Mechanical Pencil; 10-27-2013 at 07:19 PM.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: auto calculating formula or macro, not sure.

    OK but I still dont get how "20" would apply to your formla/requirement. For the "20", you use the range =AVERAGE(B32:B46), I dont see where "20" fits in with that - if you weere looking to start at the 1st 20 minutes, then that starts in row 19, not 32.

    Please explain exactly how the 20 (or whatever) fits in please? Also, you said you wanted it "in the formula and not reference a cell" - if it keeps changing, how do you intend to handle that (we can get there later, just asking)

  9. #9
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    Re: auto calculating formula or macro, not sure.

    Look at the table and chart. It displays a readout of a select ppb value over time. It starts with 20, then a 0 then an 85ppb value. The selected average of the minute data is closest to the theoretical value of 20, 0 and 85. In that order. And it has to be a continuous 15 minute average. The 3 =AVERAGE(B32:B46) formulas I have in the sample file I attached is what I am trying to automate for the 3 separate values. The times are not always the same. They change in either direction plus/minus a few minutes. I'm getting tired of repeating this calculation every day, importing the data and adjusting the current average range. That's is what I am looking to automate. Hope that helps a little.

    I still need time to fool around with the code.

  10. #10
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: auto calculating formula or macro, not sure.

    Those flat bits are all at least 30 minutes long.

    How are you picking the sample ranges? Do you want the first 15 minutes, the last 15 minutes, or the 15 minutes in the middle? Those are all going to be different.

    I've attached something that will demonstrate what I mean.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: auto calculating formula or macro, not sure.

    See the attached spreadsheet which may be close to the answer you seek.

    I got lucky and may have found a way to automate the 'Starting Point' selection process for
    each of the three theoretical values. I added 'Standard Deviations' for 15 minute intervals
    in 'Column C' of the spreadsheet. They are not used for anything (and can be removed), however
    they seem to indicate that a 'Starting Point' can be obtained by finding the 'Potential Start Row' that
    has the LOWEST '15 mintue Standard Deviation' that is below an 'arbitrary threshhold value'.

    All the 'Starting Points' you used had '15 minute Standard Deviation' values
    less than 0.06. I set the 'arbitrary threshhold value' to 0.20 and seemed to be successful in
    performing the calculations. You may want to adjust my algorithm to suit your purposes (e.g. you may
    want the data more centered).
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    Re: auto calculating formula or macro, not sure.

    Quote Originally Posted by ben_hensel View Post
    How are you picking the sample ranges? Do you want the first 15 minutes, the last 15 minutes, or the 15 minutes in the middle?
    I understand.

    This is where the theoretical value comes into play. I am looking for consecutive 15 minutes average closest to the theoretical value. It can be any 15 consecutive minute average. Usually its the average closest to the end.

  13. #13
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: auto calculating formula or macro, not sure.

    Since the solution I posted earlier today is based on the 15 minute period with the lowest standard deviation, it should give you exactly what you want.

    Lewis

  14. #14
    Registered User
    Join Date
    09-22-2013
    Location
    New England
    MS-Off Ver
    Excel 2007, 2010 & 2013
    Posts
    24

    Re: auto calculating formula or macro, not sure.

    This looks and works good. I'll fool around with it and try to expand upon it. Thanks

  15. #15
    Registered User
    Join Date
    03-10-2014
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: auto calculating formula or macro, not sure.

    Hi LJMetger, Thanks a lot. I browsed the code and I will definitely try it out. Thanks a lot for such good insight!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create Auto-Calculating Cell and Assign Cell Values Based on a Macro
    By Titanium Fox in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2013, 12:00 AM
  2. Replies: 1
    Last Post: 01-27-2013, 11:05 AM
  3. Formula calculating 'on the fly' or a vba macro
    By dziabdak in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-26-2012, 08:19 AM
  4. Auto-Run Macro from a Formula Value
    By wlr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-16-2008, 07:45 AM
  5. Auto Calculating Formula
    By charliefunkuk in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-16-2007, 04:46 PM

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