+ Reply to Thread
Results 1 to 6 of 6

How to calculate certain cells on two different worksheets in Excell using VB Macro?

  1. #1
    Registered User
    Join Date
    09-06-2009
    Location
    Jakarta
    MS-Off Ver
    Excel 2003
    Posts
    9

    How to calculate certain cells on two different worksheets in Excell using VB Macro?

    Dear All,

    I am a new in macro scripting. I have question on how to calculate the certain cells between 2 different worksheets based on the certain calculation parameters and the comparison result (the report) is put into the new worksheet on the same workbooks.

    1) Worksheet1 contains: DEPTH, G1, C1, N1, D1, S1, SR1, MR1, DR1
    2) Worksheet2 contains: DEPTH, G2, C2, N2, D2, S2, SR2, MR2, DR2

    Expected result should be put in Worksheet3: DEPTH, G1, G2, calculation(G1 and G2), CI1, C2, calculation(C1 and C2), so on until the last columns.
    (Please find example on attached file "Test_Data.xls)

    What I have done is to create a template to be filled in by copy and paste DEPTH, G1, G2 on worksheet1, DEPTH, C1, C2 on worksheet2, so on (attached file "Template_QC.xls"). Then I create a calculation macro for each of those worksheets separately to calculate the difference and color them . The calculation macro that I used is as follows:

    Please Login or Register  to view this content.
    That macro above is applied to all worksheets, except the calculation function and number mentioned in "If Cells(iRow, "D").Value >= 2 Or Cells(iRow, "D").Value <= -2" are different from one worksheet to the other

    In other words it is still a bit manual works. Now, how can I automatically calculate my 2 worksheets based on my calculation parameters above and put the resulted report in worksheet3 using VB Macro in my workbook?

    Regards,
    WiD
    Attached Files Attached Files
    Last edited by wdn1508; 09-09-2009 at 05:05 PM. Reason: To comply Rule 3 of Forum Rules

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to calculate certain cells on two different worksheets in Excell using VB Mac

    Based on the order of the data in the two worksheets ACTUALLY being the same (row 2 on both sheets go together), this macro will assemble your Calculation Report for you without the need for a "loop" to apply the conditional coloring.

    Give it a try on a more complete data set.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-08-2009 at 07:36 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-06-2009
    Location
    Jakarta
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to calculate certain cells on two different worksheets in Excell using VB Mac

    Quote Originally Posted by JBeaucaire View Post
    Based on the order of the data in the two worksheets ACTUALLY being the same (row 2 on both sheets go together), this macro will assemble your Calculation Report for you without the need for a "loop" to apply the conditional coloring.

    Give it a try on a more complete data set.
    Please Login or Register  to view this content.
    Hi JB,

    Great..Many thanks..I tested using a sample data and it works!

    On the Formulas and Formatting, how can I put different formulas on the code, because on the calculation report, the expected result actually should be based on different parameters and formula (the last three are division, not subtraction):

    1) Rpt.D2 = (dsh2.B2-dsh1.B2). If the result is => 2 or <= -2, cell color is red. Else is green
    2) Rpt.G2 = (dsh2.C2-dsh1.C2). If it is => 0.01 or <= -0.01, it should be red, Else is green
    3) Rpt.J2 = (dsh2.D2-dsh1.D2). If it is => 0.009 or <= -0.009, it is red, Else is green
    4) Rpt.M2 = (dsh2.E2 - dsh1.E2). If it is => 0.005 or <= -0.005 it is red, else is green
    5) Rpt.P2 = (dsh2.F2 - dsh1.F2), If it is =>3 or <=-3 then red, else green
    6) Rpt.S2 = (dsh2.G2 / dsh1.G2). If it is =>1.05 or <=0.99 then red, else green
    7) Rpt.V2 = (dsh2.H2 / dsh1.H2), If it is =>1.05 or <=0.99 then red, else green
    8. Rpt.Y2 = (dsh2.I2 / dsh1.I2), If it is =>1.05 or <=0.99 then red, else green

    Regards,
    WiD

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to calculate certain cells on two different worksheets in Excell using VB Mac

    Try this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-06-2009
    Location
    Jakarta
    MS-Off Ver
    Excel 2003
    Posts
    9

    Thumbs up Re: How to calculate certain cells on two different worksheets in Excell using VB Mac

    JB,

    Thanks again..It works!
    It is solved now..btw how to mark this thread already "SOLVED"?

    Regards,
    WiD
    Last edited by wdn1508; 09-09-2009 at 01:55 AM.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to calculate certain cells on two different worksheets in Excell using VB Mac

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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