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
Bookmarks