Exponential Trend With Missing Numbers

lbird2

Board Regular
Joined
Dec 10, 2014
Messages
78
Office Version
  1. 365
Platform
  1. Windows
OK, I think I have a tough one. Probably not for you guys!

Let's say I have the following data set in two rows where the top row are the x's and the second row the y's. Like this:

123456
153014181046108811371045

<tbody>
</tbody>

Assume the first cell is A1.
The following formulas will get me the two values I need to calculate an exponential trendline y = c *e ^(b * x)

c=EXP(INDEX(LINEST(LN(A1:F1),A2:F2),1,2))
b=INDEX(LINEST(LN(A1:F1),A2:F2),1)

If I do this in a chart, I will match. In a chart if I remove a value, say the 1046, it will recalculate c and b and display the adjusted trend.

The formula however will give me an error.

Now finally to my question: How can I alter my formulas to recalculate properly if I remove one or more values?

I hope I stated that clearly enough :(

Thanks.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
LINEST and a lot of other math functions are intolerant of non-numeric values; charting is more forgiving.

Short of using VBA to calculate a packed array, you just need to close up the gaps.
 
Upvote 0
OK, here's a way:

Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
1​
1​
2​
3​
4​
5​
6​
b
log(c)
2​
1530​
1418​
1046​
1088​
1137​
1045​
-0.07227​
7.340073​
H2:I2: {=LINEST(LN(INDEX(v(CloseColumns(A1:F2)), 2, 0)), INDEX(v(), 1, 0))}
3​
1540.825​
I3: =EXP(I2)
4​
5​
6​
1​
2​
3​
4​
5​
6​
b
log(c)
7​
1530​
1418​
1088​
1137​
1045​
-0.07822​
7.395596​
H7:I7: {=LINEST(LN(INDEX(v(CloseColumns(A6:F7)), 2, 0)), INDEX(v(), 1, 0))}
8​
1628.796​
I8: =EXP(I7)

It uses two UDFs: CloseColumns, which closes up the gaps for missing numbers,

Code:
Function CloseColumns(r As Range, _
                      Optional iMode As Long = 1) As Variant
  ' shg 2015
  ' Returns a variant array comprising the filled rows of r

  ' iMode
  '   1     keep numbers
  '   2     keep strings
  '   3     keep numbers & strings
  '   4     keep Booleans
  '   5     keep Booleans & numbers
  '   6     keep Booleans & strings
  '   7     keep everything except empty & errors

  Const iNum        As Long = 1
  Const iStr        As Long = 2
  Const iBoo        As Long = 4

  Dim av            As Variant
  Dim avOut         As Variant

  Dim iR            As Long
  Dim iW            As Long
  Dim iTop          As Long
  Dim jR            As Long
  Dim jTop          As Long
  Dim jW            As Long

  av = r.Value2
  iTop = UBound(av, 1)
  jTop = UBound(av, 2)

  Do While jR < jTop
    jR = jR + 1
    For iR = 1 To UBound(av, 1)
      Select Case VarType(av(iR, jR))
        Case vbEmpty, vbError
          Exit For
        Case vbDouble
          If (iMode And iNum) = 0 Then Exit For
        Case vbString
          If (iMode And iStr) = 0 Then Exit For
        Case vbBoolean
          If (iMode And iBoo) = 0 Then Exit For
      End Select
    Next iR

    If iR <= iTop Then
      ' close up
      For jW = jR To jTop - 1
        For iR = 1 To UBound(av, 1)
          av(iR, jW) = av(iR, jW + 1)
        Next iR
      Next jW
      jTop = jTop - 1
      jR = jR - 1
    End If
  Loop

  ReDim avOut(1 To UBound(av, 1), 1 To jTop)
  For jR = 1 To jTop
    For iR = 1 To UBound(av, 1)
      avOut(iR, jR) = av(iR, jR)
    Next iR
  Next jR

  CloseColumns = avOut
End Function

And a wonderful little function V, which avoids need to run CloseColumns more than once in a formula:

Code:
Public Function V(Optional vInp As Variant) As Variant
  ' Stephen Dunn 2002
  Static vSav       As Variant

  If Not IsMissing(vInp) Then vSav = vInp
  V = vSav
End Function

There a complementary function CloseRows if anyone is interested.
 
Upvote 0
Wow shg! Thanks for going above and beyond. I'll give this a shot tomorrow. I'll let you know how it works.
 
Upvote 0
Hi shg,

I realise this is 4 years old... but is there a way to do this if the X and Y aren't in adjacent rows?
I'm trying to show growth rates over time at 50+ sites in a way that I can easily update as new data is available.
I'm using a fixed range of consecutive years, not every site will have data for each year.

This is what I'm trying to do -
YEARGROWTH
SITE12345678910Exp (%)Exp R^2LinearLin R^2
A1641721921821791932011992.60.740450.7424
B7912151821275521.30.929340.7089
C1426312535613987452121.40.95955120.9965
D4366257348219561007124511.60.9824840.9643

<tbody>
</tbody>

Thanks!! I've looked everywhere online and your post was the closest I've gotten!
 
Upvote 0

Forum statistics

Threads
1,215,569
Messages
6,125,600
Members
449,238
Latest member
wcbyers

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