HOW TO PRINT PYRAMID PATTERN “*” USING VBA CODE

Share Now


Problem Statement

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

Approach

  • 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
Excel VBA Python Gurgaon

SOLUTION


Sub PrintPyramid()
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 = "*"
Next
Next
'Autofit Columns
Range("j1").CurrentRegion.Select
Selection.Columns.AutoFit
Range("j1").Select
Application.ScreenUpdating = True


End Sub

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


Share Now
November 14, 2019

0 responses on "HOW TO PRINT PYRAMID PATTERN “*” USING VBA CODE"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Tableau Training in Delhi

    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.

    Address

    NM 23, SECTOR 14, OLD DLF COLONY,
    GURGAON (HARYANA)
    0124- 4601426

    Featured Testimonial

    The experience...Read more

    Karan Jeena (HR Analyst)

    ZS Associates

    EC Analytics Consulting @ 2019 ALL RIGHTS RESERVED