J
Jim G
I use the following code to enter formulae into a sheet that has three
columns for each month (Actual, Adjustment,Net-starting at row 12). Each
month new data is added to the Data Sheet. The formulae are added to each
line (starting at row 13)and the month actuals updated. Is it possible to
enter the result of the formula in each row or should I just copy the column
and paste values after the main code has run?
I would also appreciate any ideas on error handling to allow the use to back
out if they don't want to make the choice of starting cell.
The data sheet has a date that I would like to validate against the column
date (cell above Actual-row 11) and warn or terminate the code.
--------------------------------------------
Option Explicit
Sub Formula()
' Enters formulas in current month "ACTUAL" column to retreive PFRM data
Dim col As String
Dim adjCol As String
Dim Col2 As String
Dim iRow As Long, r As Long
Dim Net As Range
Dim rngInput As Range
Dim CalcType As Variant
Dim ProjResult As String
Dim Projnet As String
Dim Lastrow As Long
Worksheets("Cheops").Select
Rows(13).Select 'to ensure the screen is at the first row for input
With Application
CalcType = .Calculation
.Calculation = xlCalculationManual
End With
' to select the column of the current month
Set rngInput = Application.InputBox("Select Starting Cell in Highlighted
Row", Type:=8)
Application.ScreenUpdating = False
col = Split(rngInput.Address, "$")(1)
Col2 = Split(rngInput.Offset(0, 2).Address, "$")(1)
adjCol = Split(rngInput.Offset(0, 1).Address, "$")(1)
iRow = rngInput.Row
ProjResult = "=SUMIF(Data!$A:$A,$A" & iRow &
",Data!$D:$D)+SUMIF(Data!$C:$C,$C" & iRow & ",Data!$D:$D)"
Debug.Print (ProjResult) ' temp test the for result
Projnet = "=(" & col & iRow & "+" & adjCol & iRow & ")"
With Worksheets("Cheops")
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range(col & iRow & ":" & col & Lastrow).Value = ProjResult
.Range(Col2 & iRow & ":" & Col2 & Lastrow).Formula = Projnet
End With
With Application
.ScreenUpdating = True
.Calculation = CalcType
End With
End Sub
columns for each month (Actual, Adjustment,Net-starting at row 12). Each
month new data is added to the Data Sheet. The formulae are added to each
line (starting at row 13)and the month actuals updated. Is it possible to
enter the result of the formula in each row or should I just copy the column
and paste values after the main code has run?
I would also appreciate any ideas on error handling to allow the use to back
out if they don't want to make the choice of starting cell.
The data sheet has a date that I would like to validate against the column
date (cell above Actual-row 11) and warn or terminate the code.
--------------------------------------------
Option Explicit
Sub Formula()
' Enters formulas in current month "ACTUAL" column to retreive PFRM data
Dim col As String
Dim adjCol As String
Dim Col2 As String
Dim iRow As Long, r As Long
Dim Net As Range
Dim rngInput As Range
Dim CalcType As Variant
Dim ProjResult As String
Dim Projnet As String
Dim Lastrow As Long
Worksheets("Cheops").Select
Rows(13).Select 'to ensure the screen is at the first row for input
With Application
CalcType = .Calculation
.Calculation = xlCalculationManual
End With
' to select the column of the current month
Set rngInput = Application.InputBox("Select Starting Cell in Highlighted
Row", Type:=8)
Application.ScreenUpdating = False
col = Split(rngInput.Address, "$")(1)
Col2 = Split(rngInput.Offset(0, 2).Address, "$")(1)
adjCol = Split(rngInput.Offset(0, 1).Address, "$")(1)
iRow = rngInput.Row
ProjResult = "=SUMIF(Data!$A:$A,$A" & iRow &
",Data!$D:$D)+SUMIF(Data!$C:$C,$C" & iRow & ",Data!$D:$D)"
Debug.Print (ProjResult) ' temp test the for result
Projnet = "=(" & col & iRow & "+" & adjCol & iRow & ")"
With Worksheets("Cheops")
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range(col & iRow & ":" & col & Lastrow).Value = ProjResult
.Range(Col2 & iRow & ":" & Col2 & Lastrow).Formula = Projnet
End With
With Application
.ScreenUpdating = True
.Calculation = CalcType
End With
End Sub