Tuesday, 29 September 2015

How to create a Faster Fibonacci Function in Excel with VBA

How to create a Faster Fibonacci  Function in Excel

In mathematics, the sequence of number 1,1,2,3,5,8,13,21,34,56.... is known as the Fibonacci numbers or sequence. Read More Here


I would like to show you how to write faster Fibonacci generating function in excel

Open your visual basic editor and enter the following code. Visit this post to learn how to enable developer options in Excel

Learn how to create your own Excel Functions HERE

 
Option Explicit
' This set a maximum number for the sequence. 
' You can change it but use the right datatype
' learn Excel DataTypes HERE
Dim f(500) As Double  

Function fib(n As Double)
 If n = 0 Or n = 1 Then
    fib = n
  ElseIf f(n) > 0 Then
        fib = f(n)
    Else
        f(n) = fib(n - 1) + fib(n - 2)
        fib = f(n)
    End If
End Function

Go to your Excel Workbook and use the function as follows


No comments :

Post a Comment