View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Hannes Hannes is offline
external usenet poster
 
Posts: 30
Default Compare two sheets, identify values, calculate delta - Pls hel

Hi Per,

still the same error message. Any ideas?

Thanks!


"Per Jessen" wrote:

Hi

I think it's because the line miss a ".Value" at the end. Try this:

Delta = sh1.Cells(f.Row, "M").Value - sh2.Cells(f.Row, "m").Value

Best regards,
Per

"Hannes" skrev i meddelelsen
...
Unfortunately it doesn't work.
I get the error at "Delta = sh1.Cells...": False compilation - variable or
procedure instead of module expected.

"Per Jessen" wrote:

Hi

Try this:

Sub Compare_Calculate()
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")

sRow = 3
eRow = Range("A3").End(xlDown).Row
For r = sRow To eRow
d1 = sh1.Cells(r, "A").Value
d2 = sh1.Cells(r, "C").Value
d3 = sh1.Cells(r, "D").Value

Set f = sh2.Columns("A").Find(what:=d1)
If Not f Is Nothing Then
If Range(f.Address).Offset(0, 2) = d2 And _
Range(f.Address).Offset(0, 3) = d3 Then
Delta = sh1.Cells(f.Row, "M").Value - sh2.Cells(f.Row, "m")
Cells(f.Row, "N") = Delta
End If
End If
Next
End Sub

Regards,
Per

"Hannes" skrev i meddelelsen
...
Hi,

I need to develop a macro which has to first identify and then
calculate
between two sheets. I just started to learn to program macros so please
help
me with this one (as it seems far to complex to do that on my own).

Details:
The macro starts in sheet1 in row 3 takes the values in this row of
column
A, C, D and compares them with sheet2 with the same columns but any
row.
If
the values match the macro should go on and subtract the values in
Column
M
in sheet2 from sheet1 and output the result in Column N in row 3 in
sheet1.
If the macro does not find a match of row 3 of sheet1 in sheet2 it
should
go
on to the next row in sheet1 and start with the comparison of column A,
...
and so on.

Many thanks for any support!!