This is an overview:
Introduction to the Fibonacci Sequence
The Fibonacci sequence is a set of integers starting with 0 and 1. The next number in the sequence is found by adding the 2 numbers before it. So, our 1st and 2nd Fibonacci numbers are 0 and 1. The next number is 0+1=1. The next number will be 1+1=2.
Method 1 – Using a Mathematical Formula to Create a Fibonacci Sequence in Excel
Steps:
- Enter 0 and 1 in B5 and B6.
- Select B7 and enter the formula:
=B5+B6
- Press Enter.
1 is the third number of the sequence.
- Drag down the Fill Handle to see the result in the rest of the cells.
This is the output.
Method 2 – Running an Excel VBA Code to Create a Fibonacci Sequence in Excel
Step 1:
- Go to the Developer tab and click:
Developer → Visual Basic
- In the Microsoft Visual Basic for Applications window, go to:
Insert → Module
Step 2:
- In the fibonacci_number module, enter the VBA code.
Option Explicit
Private Function FibNum(nthFib As Double) As Double
Dim x As Double
Dim y As Double
x = 1.618034 ^ nthFib - (1 - 1.618034) ^ nthFib
y = x / Sqr(5)
FibNum = Round(y)
End Function
Function FibonacciSeries(StartSr As Double, EndSr As Double) As Double()
Dim a As Double, b As Double, xy As Double
Dim xy() As Double
ReDim Preserve xy(EndSr - StartSr, 0)
xy = 0
For a = StartSr To EndSr
b = FibNum(a)
arr(xy, 0) = b
xy = 1 + xy
Next a
FibonacciSeries = arr
End Function
Sub Fibonacci_Number()
End Sub
- To run the VBA, go to:
Run → Run Sub/UserForm
- Go to the Excel sheet, select B5, and enter the function:
=FibonacciSeries(0,9)
- Press enter.
You will see the series of the first 10 numbers.
Things to Remember
- You can open the Microsoft Visual Basic for Applications window by pressing Alt + F11 or ALT + L + V.
- To enable the Developer tab, go to:
File → Option → Customize Ribbon
Download Practice Workbook
Download the practice workbook.
<< Go Back to | Excel for Math | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!