montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hello, Everyone Hoping all be safe.
I have a complex task, I don’t Know how to resolve this.
EXCELENT code provided by StephenCrump Well-known Member Worked just perfectly Beautiful, for the objective I ask for.
Now, the code, loop the TREND formula and compare results with the input data and count them, until here perfect,
So, what is my problem?
In this moment I need no just the trend formula, I need the six coefficient trend lines to plugging in this code (“no clue” expecially with the Linest”, Sorry)
But, EACH formula must display the results in separate sheets.
Trend on sheet 1, Exponential Sheet 2, Linear Sheet 3, Logarithmic s4,
Polynomial in 5, power in 6 and moving average on 7.
And one more thing, I would like also to change a line (already tryed, do not work)
Set rngData = Range("B3:G2720") for something like: Cells(Rows.Count, "A").End(xlUp).Row
in order to read Just the array (dynamic) that is active at the moment.
Thank you for reading this.
I have a complex task, I don’t Know how to resolve this.
EXCELENT code provided by StephenCrump Well-known Member Worked just perfectly Beautiful, for the objective I ask for.
Now, the code, loop the TREND formula and compare results with the input data and count them, until here perfect,
So, what is my problem?
In this moment I need no just the trend formula, I need the six coefficient trend lines to plugging in this code (“no clue” expecially with the Linest”, Sorry)
But, EACH formula must display the results in separate sheets.
Trend on sheet 1, Exponential Sheet 2, Linear Sheet 3, Logarithmic s4,
Polynomial in 5, power in 6 and moving average on 7.
And one more thing, I would like also to change a line (already tryed, do not work)
Set rngData = Range("B3:G2720") for something like: Cells(Rows.Count, "A").End(xlUp).Row
in order to read Just the array (dynamic) that is active at the moment.
Thank you for reading this.
VBA Code:
Sub Monte_carlo_2012()
Dim rngStart As Range, rngData As Range
Dim Diff1 As Long, Diff2 As Long, NoRows As Long, NoCols As Long, i As Long
Dim s As String
Set rngData = Range("B3:G2720") 'Cells(Rows.Count, "A").End(xlUp).Row
NoRows = rngData.Rows.Count
NoCols = rngData.Columns.Count
Diff1 = 8: Diff2 = 35
Set rngStart = Range("I3").Resize(, NoCols)
For i = Diff1 To Diff2
With rngStart.Offset(, (NoCols + 1) * (i - Diff1)).Resize(NoRows - i)
.Rows(0).Formula = "=SUMPRODUCT(--(" & rngData.Resize(NoRows - i, 1).Address(0, 0) & "=" & .Columns(1).Address(0, 0) & "))"
.Rows(0).Font.Bold = True
.Formula = "=TRUNC(TREND(" & rngData.Resize(i + 1, 1).Address(0, 0) & "))"
s = .Cells(1, 1).Address(0, 0)
With .FormatConditions
.Delete
.Add Type:=xlExpression, Formula1:="=" & rngData(1, 1).Address(0, 0) & "=" & s
.Item(1).Interior.Color = vbYellow
End With
End With
Next i
End Sub