+ Reply to Thread
Results 1 to 8 of 8

How to automate a repetitive calculation on 3 sequential cells

  1. #1
    Registered User
    Join Date
    06-23-2009
    Location
    Southern California, US
    MS-Off Ver
    Excel 2007
    Posts
    7

    Smile How to automate a repetitive calculation on 3 sequential cells

    Dear forum members,

    Thank you so much for taking the time to read this. I work for a science research lab and am trying to change some code that was written by someone before me in order to analyze thousands of data sets that would take forever to do by hand. I am hoping one of the very brilliant people on here may be able to help me.

    Currently the code that I have takes an x # of cells (variable is called numTrPSess) and sums them together and then writes that sum into the cell of a new sheet.

    Rather than summing the number of cells defined by numTrPSess I need a different function calculated. numTrPSess needs to be a constant of 3 and I need those 3 cells to be calculated as such:

    (Cell1 - Cell3)*(Cell1)

    So for something like cells A1,A2,A3 with values of 6,5,4 respectively, I would need this macro to do (A1 - A3)*(A1) and therefore print out the value of (6 - 4) * (6) = 12.

    Here is my current code: http://pastie.org/1035435

    Please Login or Register  to view this content.
    Thank you so much to anyone who can provide any assistance!
    Last edited by Excel4Lab; 07-08-2010 at 12:25 AM.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to automate a repetitive calculation on 3 sequential cells

    Hi,

    I don't know if the answer is as simple as replacing
    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    abousetta

  3. #3
    Registered User
    Join Date
    06-23-2009
    Location
    Southern California, US
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to automate a repetitive calculation on 3 sequential cells

    Thank you for your response!

    I may not have explained this correctly -- let me try to clarify.

    The way the macro is currently coded, it asks "How many trials should be summed into each session?" and we have usually put in 3. The reason being is that we always have 3 trials per session. Then we have in the past wanted to sum up the values from each trial into 1 large session value so if we had 30 trials, we'd have those 30 trials summed up into 10 sessions ( each sessiong with a group of 3 trials each).

    Now what I'm trying to do is instead of having the macro simply add trial1+trial2+trial3 on each group of 3 cells that it encounters is instead to ditch the 2nd cell in each group and output the answer to the equation of (cell1 - cell3) * (cell1).

    If this doesn't make sense please do ask -- and THANK YOU for looking at this!

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to automate a repetitive calculation on 3 sequential cells

    Hi...

    I'm trying to isolate the part of the code that needs modification? Is this it?

    Please Login or Register  to view this content.
    Also if you could post a dummy workbook then it would be helpful to visualize what you are doing exactly.

    abousetta

  5. #5
    Registered User
    Join Date
    06-23-2009
    Location
    Southern California, US
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to automate a repetitive calculation on 3 sequential cells

    Yes I believe that is the code that needs editing.

    I have attached a sample workbook. The sheet Data Targeted shows the trials by each subject (where each subject has 3 trials in a row, before the next subject has a trial). In this worksheet, you will see that 108 subjects have 14 sessions of 3 trials each (a total of 42 trials per subject). In the worksheet Data By Session, those 42 trials per subject are summed into 14 blocks of 3 trials each using this macro.

    Rather than sum those 42 trials into 14 blocks of 3 trials, I want to take those 42 trials per subject and calculate 14 values from each group of 3 trials using the equation of (Trial1 - Trial3) * (Trial1).

    Thank you!
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: How to automate a repetitive calculation on 3 sequential cells

    Thanks for posting the wokbook. I will try and have a look at it tomorrow and see if I can help.

    If anyone can help before then, please feel free to jump in.

    Good luck Excel4Lab.

    abousetta

  7. #7
    Registered User
    Join Date
    06-23-2009
    Location
    Southern California, US
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to automate a repetitive calculation on 3 sequential cells

    Thank you!

  8. #8
    Registered User
    Join Date
    06-23-2009
    Location
    Southern California, US
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How to automate a repetitive calculation on 3 sequential cells

    Bump! Anyone able to help? Thank you!

+ 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