Now today we are going to create pyramid 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
- Will use two loops here, one to jump rows and second to print “*”.
- In second section we have also adjusted column width using autofit method
Dim i As Integer
Dim j As Integer
Application.ScreenUpdating = False
For i = 1 To 10
For j = 10 - i + 1 To 9 + i
Cells(i, j).Value = "*"
Application.ScreenUpdating = True
STEPS TO PERFORM
- Go to developer Tab else Press Alt + F11
- Click on Visual Basic icon
- Go to Insert click on Module
- Paste below code in standard module