My first table, named 'MAIN' (a comma indicating a different column):
1,2,3
4,5,6
5,7,9
The third row is calculated using the SUM function. I am trying to copy this into another worksheet named 'Static Data' but the third row should only contain the numbers 5,7,9 not the corresponding SUM formulas.
The code below, takes this data from MAIN and pastes it into the 'Static Data' worksheet.
Public Sub CopyMain()
Dim i As Long
i = 1
With Worksheets("Static Data")
Cells.ClearContents
Worksheets(i).Range("A1").CurrentRegion.Copy .Range("A1")
.Range("A1").CurrentRegion.Value = .Range("A1").CurrentRegion.Value
End With
End Sub
I use the i variable since MAIN will always be the first worksheet in the workbook.
This copies the data from MAIN to Static Data when run from any sheet apart from MAIN.
It fails when run from MAIN and leads to all contents in MAIN being deleted.