workbook problem
HI! I've got code
Sub Transpose()
'declarations
Workbooks.Add
Set destination = ActiveWorkbook.Sheets(1)
Set difference = ActiveWorkbook.Sheets(2)
ThisWorkbook.Activate
'Code to transpose data.it's a loop
'Then another code.
Set Target_Cell = destination.Range("C1")
Set Source_Cell = difference.Range("c1")
Const COMPANY_OFFSET = 3
Const COMPANY_COUNT = 3
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
My problem is,the 2nd code suppose to refer to the new workbook that has been added but it refer to the current activeworkbook. PLease help.
|