+ Reply to Thread
Results 1 to 3 of 3

VBA Macro required: Calculating an average then substracting it from a range of cells

  1. #1
    Registered User
    Join Date
    07-20-2010
    Location
    Ontario
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA Macro required: Calculating an average then substracting it from a range of cells

    I am preparing a QA/QC assistance program for our analytical chemistry lab. I need to subtract the ‘blank sample’ values from the actual samples. I have one worksheet that contains all of the samples and blank samples (listed by row). The value for the sample = sample – average of the blank values.


    This is where it gets complicated: The average of the ‘sample blanks’ that bracket the ‘sample set’ is use to correct for that sample set. [keeping in mind that the samples and sample blanks may be in different rows as the order is not static and raw data could have +1000 samples (rows) and +500 properties (columns)]


    i need a code that does something like this:

    COLUMN A:

    Blank1
    Sample1
    Sample2
    Sample3
    Sample4
    Blank2
    Sample5
    Sample6
    Sample7
    Sample8
    Sample9
    Sample10
    Sample11
    Blank12
    COLUMN B and so on …:
    Numerical values for the property .. filled from B2: to the end (could be B2:PP5000)!
    What I want the macro to do (in a new Sheet)

    Column A will be the same

    Column B and so on …
    Blank1 value
    Sample1 value – average(Blank1,Blank2)
    Sample2 value – average(Blank1,Blank2)
    Sample3 value – average(Blank1,Blank2)
    Sample4 value – average(Blank1,Blank2)
    Blank2 value
    Sample5 value – average(Blank2,Blank3)
    Sample6 value – average(Blank2,Blank3)
    Sample7 value – average(Blank2,Blank3)
    Sample8 value – average(Blank2,Blank3)
    Sample9 value – average(Blank2,Blank3) Sample10 value – average(Blank2,Blank3) Sample11value – average(Blank2,Blank3)
    Blank12 value

    Any hints to get me started?
    I am somewhat fluent in VBA…

    Thank you for your help!
    A.
    Last edited by aimeemia; 07-20-2010 at 05:25 PM. Reason: title change

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: VBA Macro required: Calculating an average then substracting it from a range of c

    the data is like this (row 1 contains column headings) from A1 to B14

    A B
    1
    a 2
    s 3
    d 4
    f 5
    6
    g 7
    h 8
    j 9
    k 10
    l 11
    m 12
    13

    now if you run the macro "test" you will get the results in column C. (if you want you can delete column B-But I suggest keep that column so that you will know what is the original values)

    Please Login or Register  to view this content.
    after running the macro the data will be

    A B C
    1 3.5
    a 2 3.5
    s 3 3.5
    d 4 3.5
    f 5 3.5
    6 9.5
    g 7 9.5
    h 8 9.5
    j 9 9.5
    k 10 9.5
    l 11 9.5
    m 12 9.5
    13

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Macro required: Calculating an average then substracting it from a range of c

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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