Hi--
You need 2 loops, one to calculate the deltas for each column and the other the cycle through the companies
The code below is my sample solution. Note that the names are more meaningful, use of constants, elimnation of several variables without loss of clarity, use of offsets for relative ranges, only 2 uses of absolute ranges, etc.
If there is a lot of data, you may want to put all the results for
a company into an array and then copy the array to the target sheet in a single command
Enjoy!
Barry
<code>
Sub Get_Differences()
Dim j As Long
Dim Source_Cell As Range, Target_Cell As Range
Dim Source, Target As Range
Const COMPANY_OFFSET = 3
Const COMPANY_COUNT = 3
Sheet3.Activate
Set Source_Cell = Sheet8.Range("C1")
Set Target_Cell = Sheet2.Range("C1")
For j = 1 To COMPANY_COUNT ' Loop through companies
'Set range of Source from top to next to bottom of values
Set Source = Range(Source_Cell,
Source_Cell.End(xlDown).Offset(-1, 0))
Set Target = Target_Cell
Source.Select
For Each Cell In Source
Target.Value = Cell.Offset(1, 0) - Cell.Value
Set Target = Target.Offset(1, 0) ' Move target to next row
Next
Set Source_Cell = Source_Cell.Offset(0, COMPANY_OFFSET)
Set Target_Cell = Target_Cell.Offset(0, COMPANY_OFFSET)
Next j
End Sub
</code>
|