# HOW TO PRINT A PASCAL TRIANGLE USING VBA CODE

Share Now

#### Problem Statement

Now today we are going to create Pascal Triangle using VBA. This is not a reporting problem statement but in some of the organizations in an interview, they ask this question to understand the programming capabilities

This is an interesting nested loop exercise

#### Approach

In the Pascal triangle, every element makes sum of the element directly above it and the element to the left of the element directly above it

The table will fill in series of numbers starting from 1 to 25. In each row, there are five numbers.
To the run the example program, you will need one Form and one Command Button.

SOLUTION

` Option Explicit`

Private Sub CommandButton1_Click()

Dim i(10, 10) As Integer
Dim r, j As Integer
i(0, 0) = 1
i(1, 0) = 1
i(1, 1) = 1
For r = 2 To 10
i(r, 0) = 1
For j = 1 To r

i(r, j) = i(r – 1, j – 1) + i(r – 1, j)
Next
Next
For r = 0 To 10

For j = 0 To r
Cells(r + 1, j + 1) = i(r, j)
Next
Next
End Sub

#### STEPS TO PERFORM

• Go to developer Tab else Press Alt + F11
• Click on Visual Basic icon
• Go to Insert click on Module

Share Now
November 14, 2019

### 0 responses on "HOW TO PRINT A PASCAL TRIANGLE USING VBA CODE"

EC Analytics will help your business make better decisions by providing expert-level business intelligence (BI) services. Forecasting, strategy, optimization, performance analysis, trend analysis, customer analysis, budget planning, financial reporting and more. EC Analytics also offers Advanced Data Analytics training in corporate and retail.