arbrandt / OPGEE

Oil Production Greenhouse Gas Emissions Estimator
18 stars 3 forks source link

PasteSpecial method of Range class failed #492

Open wennanlong opened 1 year ago

wennanlong commented 1 year ago

Fixed it by using the following code in the reset (VBA)

Sub Reset_overall() 'Subroutine that resets the results sheet by copying from a hidden worksheet. Worksheets("ResetResults").Range("G9:SM309").Copy Worksheets("Results").Range("G9:SM240").PasteSpecial Paste:=xlPasteAll Application.CutCopyMode = False Application.CutCopyMode = True

'Reset the VFF sheet by copying from a hidden worksheet Worksheets("ResetVFF").Range("C11:SI79").Copy Worksheets("VFF Summary").Range("C11:SI79").PasteSpecial Paste:=xlPasteAll Application.CutCopyMode = False Application.CutCopyMode = True

'Reset the uncertainty sheet by copying from below the relevant range Worksheets("Uncertainty").Range("H1055:SN2055").Copy Worksheets("Uncertainty").Range("H51:SN1050").PasteSpecial Paste:=xlPasteAll Application.CutCopyMode = False Application.CutCopyMode = True

Worksheets("Uncertainty").Range("H37:SN48").ClearContents

End Sub

Sub Reset_between_uncertainty_runs() 'Subroutine that resets the results sheet by copying from a hidden worksheet. Worksheets("ResetResults").Range("G9:SM309").Offset(0, FieldIndex).Copy Worksheets("Results").Range("G9:SM309").Offset(0, FieldIndex).PasteSpecial Paste:=xlPasteAll Application.CutCopyMode = False Application.CutCopyMode = True

End Sub

Sub Populate_overall()

' Populates "Results" worksheet using user inputs data from the "Inputs" worksheet Application.Calculation = xlCalculationManual Worksheets("Results").Activate 'Write the number of fields to be assessed Worksheets("Results").Range("C2") = Worksheets("Inputs").Range("C2").Value Worksheets("Results").Range("B2") = Worksheets("Inputs").Range("B2").Value

'Iterate through fields to be assessed
For i = Worksheets("Inputs").Range("B2").Value To Worksheets("Inputs").Range("C2").Value
        Worksheets("Results").Range("G9:G115").Offset(0, i).Value = Worksheets("Inputs").Range("G9:G115").Offset(0, i).Value
Next i
Application.Calculation = xlCalculationAutomatic

End Sub

Sub Populate_between_uncertainty_runs()

' Populates "Results" worksheet using user inputs data from the "Inputs" worksheet Application.Calculation = xlCalculationManual

'Reset column of interes
Worksheets("Results").Range("G9:G115").Offset(0, FieldIndex).Value = Worksheets("Inputs").Range("G9:G115").Offset(0, FieldIndex).Value
Application.Calculation = xlCalculationAutomatic

End Sub