Results 1 to 6 of 6

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

Threaded View

  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:

    Public Sub GTemplate()
      Dim LastRow As Long, iRow As Long
      Dim diff As Double
      LastRow = Range("A1:D1").SpecialCells(xlLastCell).Row
      For iRow = 2 To LastRow
        Cells(iRow, "D").Value = Cells(iRow, "C").Value - Cells(iRow, "B").Value
        If Cells(iRow, "D").Value >= 2 Or Cells(iRow, "D").Value <= -2 Then
            Range(Cells(iRow, "D"), Cells(iRow, "D")).Select
            Selection.Interior.ColorIndex = 3
        Else
            Range(Cells(iRow, "D"), Cells(iRow, "D")).Select
            Selection.Interior.ColorIndex = 43
        End If
      Next iRow
    End Sub
    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

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