Loop is not returning nothing

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hi.
working with trendline, inserting in a loop, but I don't get any result. I already check Tushar Mehta, and excel tool set for the formulas, the formula I am now is:
Equation: y=c*x^b
c: =EXP(INDEX(LINEST(LN(y),LN(x),,),1,2))
VBA Code:
Sub T_L()
         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")
                           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
                                                         'Equation: y=c*x^b
                                                          'c: =EXP(INDEX(LINEST(LN(y),LN(x),,),1,2))
                                                                              .Formula = "= trunc(abs(EXP(INDEX(LINEST(LN(B3:B19),LN($A$3:$A$19),,),1,2))))"
                                                        
                                                         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
Thanks.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
... but I don't get any result.

Your code will give you results. I think you mean the results are not what you want?
VBA Code:
'Try replacing
.Formula = "= trunc(abs(EXP(INDEX(LINEST(LN(B3:B19),LN($A$3:$A$19)),2))))"
'with
.Formula = "= trunc(abs(EXP(INDEX(LINEST(LN(" & rngData.Resize(i + 1, 1).Address(0, 0) & "),LN(" & rngData.Offset(, -1).Resize(i + 1, 1).Address(0, 1) & ")),2))))"
 
Upvote 0
StephenCrump, Thank you for your return, I did what you say, and what I get is all the columns with #value! on every single cells.
1589504281725.png
 
Upvote 0
I am assuming from your first post that you have X-values in A3:A2720 and six sets of Y-values in B3:G2720?
 
Upvote 0
OK, let's look at the first formula produced by the code, which should be:

I3: =TRUNC(ABS(EXP(@INDEX(LINEST(LN(B3:B11),LN($A3:$A11)),2))))

What values do you have in A3:A11, and in B3:B11?
 
Upvote 0
Sorry Sir I see, when I write values on column A then I got results, Ok, Sir. I understand, Sorry. Supposedly I must have values on A because the formula say ($A$3:$A$19),,),1,
 
Upvote 0

Forum statistics

Threads
1,224,912
Messages
6,181,697
Members
453,062
Latest member
blackyblack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top