VBA for Fibonacci sequence

Alcat03

New Member
Joined
Nov 7, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I need to do a fibinoichi in excel using the developer tab and creating a button that generates the sequence. We also have to have a reset button that clears the cells and atomically make cell(1,1)= 1 and cell(2,1)= 1 and the fib button has to start with those two number and carry down the row. Can someone please show me how to code for that
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
@Alcat03 First of all there's no need to shout and don't yell that you problem is "urgent" and second please follow the forum rules and start a new question with a meaningful title.
It seems that you want "us" to do your homework or something, since you wrote "We also have to"... Well, regardless of the fact that you should at least try to solve it on your own or show us your efforts, the forum is here to help.

So, could you please be a little more specific and tell us how many Fibonacci numbers you want the VBA to generate and how or where they should be placed in a table?
 
Upvote 0
second please follow the forum rules and start a new question with a meaningful title.
Starting a new thread is against the forum rules, added to which we do not have a rule regarding suitable thread titles.
So please check the rules yourself before telling other people what to do.
 
Upvote 0
@Alcat03 First of all there's no need to shout and don't yell that you problem is "urgent" and second please follow the forum rules and start a new question with a meaningful title.
It seems that you want "us" to do your homework or something, since you wrote "We also have to"... Well, regardless of the fact that you should at least try to solve it on your own or show us your efforts, the forum is here to help.

So, could you please be a little more specific and tell us how many Fibonacci numbers you want the VBA to generate and how or where they should be placed in a table?
I’m sorry if it seem like I was yelling but I have tired over a few weeks but I have been getting no help. The Fibonacci button doesn’t have a limit of numbers to generate. What I need the button to do is take cell (1,1) =1 and then cell(2,1)=1 and add those numbers to be placed in cell(3,1) which would equal to 2 and so on down the row. I already have a rest button which keeps the first to cells 1 and will clear the rest of the numbers when done with the Fibonacci just can’t figure out the code for the Fibonacci button.
 
Upvote 0
To build Fibonacci

VBA Code:
Option Explicit

Sub Fibonacci()
    Dim rn As Long
    Dim cn As String
    Dim i As Long
    cn = Application.InputBox(prompt:="Which column to fill")
    rn = Application.InputBox(prompt:="How many lines do you wish to fill?")
    Cells(1, cn) = 1
    Cells(2, cn) = 1
    For i = 3 To rn
    Cells(i, cn) = Cells(i - 2, cn) + Cells(i - 1, cn)
    Next i
    MsgBox ("Action Completed")

End Sub

To clear Fibonacci
VBA Code:
Option Explicit

Sub ClearFibonacci()
    Dim rn As Integer, lr As Long
    Dim cn As String
    cn = Application.InputBox(prompt:="Which column to clear")
    lr = Cells(Rows.Count, cn).End(xlUp).Row
    Range(Cells(1, cn), Cells(lr, cn)).ClearContents
    MsgBox ("Action Completed")

End Sub

Attach each to a command button.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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