L
L
lev892021-11-06 11:17:06
Visual Basic
lev89, 2021-11-06 11:17:06

How to create a macro for calculating the sum of Fibonacci numbers?

You need to create a table with two columns. Let there be 10 lines in total. The first column is the serial number. The second column is a sequence of fibonacci numbers. After generating the table, you need to calculate the sum of a series of fibonacci numbers. Please help me with a solution.

Sub CreateTable()

'переменная для присвоения количества строк
Dim a As Long
a = Cells(10, 2).CurrentRegion.Rows.Count

'Добавляем строку заголовков
Cells(1, 1).EntireRow.Insert

'Указываем названия граф
Cells(1, 1) = "№ п/п"
Cells(1, 2) = "Значение"

'Добавляем сетку
Range(Cells(1, 1), Cells(a + 10, 2)).Borders.LineStyle = True

'Выделяем заголовки жирным шрифтов и применяем автоподстройку ширины столбцов
With Range(Cells(1, 1), Cells(1, 2))
.Font.Bold = True
.EntireColumn.AutoFit
End With

End Sub

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hint000, 2021-11-06
@hint000

Why is there a macro here? Formulas in a few seconds are done (column C - the sum of the first numbers):
61864c4459513513975597.png
61864c4cd376a228599755.png

L
lev89, 2021-11-06
@lev89

this is of course yes, but the question is fundamental within the framework of the discipline under study.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question