How to Create a Fibonacci Sequence in Excel – 2 Methods

This is an overview:

fibonacci sequence in excel


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.

insert 0 and 1 to create fibonacci sequence

  • Select B7 and enter the formula:
=B5+B6
  • Press Enter.

1 is the third number of the sequence.

Apply mathematical formula to create Fibonacci Sequence

  • Drag down the Fill Handle to see the result in the rest of the cells.

Apply mathematical formula to create Fibonacci Sequence

This is the output.

Apply mathematical formula to create Fibonacci Sequence


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

open visual basic window

  • In the Microsoft Visual Basic for Applications window, go to:

Insert → Module 

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

			

Insert VBA code

  • To run the VBA, go to:

Run → Run Sub/UserForm

execution of VBA code

 

  • 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.

Return of the FibonacciSeries function


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!
Mizbahul Abedin
Mizbahul Abedin

Md Mizbahul Abedin, BSc, Textile Engineering and Management, Bangladesh University of Textiles, has been working with the ExcelDemy project for 11 months. Currently working as an Excel and VBA Content Developer who provides authentic solutions to different Excel-related problems and writes amazing content articles regularly. He has published almost 20 articles in ExcelDemy. He has passions for learning new things about Microsoft Office Suite and Data analysis. Besides, he also likes to travel, photography, international politics, and read... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo