The Wayback Machine - https://web.archive.org/web/20240119132724/https://www.geeksforgeeks.org/generating-dynamic-charts-with-vba-in-excel/
Open In App
Related Articles

Generating Dynamic Charts With VBA in Excel

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

A powerful graph range is an information range that refreshes naturally when you change the information source. This unique reach is then utilized as the source information in an outline. As the information changes, the powerful reach refreshes right away which prompts an update in the outline. 

The following is an illustration of a graph that utilizes a unique outline range.

Sample Data 

Sample Data

 

Follow the further steps in Generating Dynamic Charts with VBA in Excel

Step 1: Opening the Visual Essential Window. Press ALT+F11 on your console to open the Visual Essential Window.

VBA code

 

Step 2: Embedding Another Module. Go to the Addition > Module choice in the toolbar. Click on Module. Another module called Module1 will be embedded.

VBA Module

 

Step 3: Putting the VBA Code

sub create _dynamic_ chart ()

Application . ScreenUpadting  = False

with Activesheet. shapes ( Application .caller ) .Fill.Forecolor

      If  . Brightnesss = 0 Then

          . Brightness   =  -0.150000006

   Else

           . Brightness   = 0

     End If

End With

   

Dim Sequence ( )  As String

Desired__shapes =   Array ( ” Rounded Rectangle 1″  ,  ”  Rounded Rectangle 2  ”  ,  ” Rounded Rectangle 

  For  i  = LBound ( Desired _Shapes ) To UBound ( Desired_Shapes)

         With ActiveSheet.Shapes(Desired _Shapes (i) )

              If .Fill . Forecolor.Brightness = -0.150000006  Then

                  Sequence ( UBound ( Sequence ) ) = . Text Frame2.TextRange . Characters . Text

                 ReDim Preseve Sequence ( UBound ( Series ) + 1 )

         End If

  End With

Next i 

If UBound ( Sequence ) >0 Then ReDim Preserve Sequence ( UBound ( Sequence ) – 1 )

Worksheets (“sheet 1″ ) . ListObjects ( ” Table 1 ” ). Range . AutoFilter Field  :=1

Worksheets ( ” sheet 1″). ListObjects ( “Table 1 ” ) . Range .AutoFilter _

      Field : =1 , Criterial : = Sequence  , Operator : =xl FilterValues

Application.ScreenUpadting = True

End Sub

Step 4: Saving the Workbook in XLSM Format, then return to the workbook and save it as an Excel Macro-Enabled Workbook.

Excel Macro-Enabled Workbook

 

Step 5: Run the code from the Run Sub/UserForm choice in the toolbar.

Run VBA

 

You’ll find a powerful graph made in view of the table in Sheet2 of the worksheet.

Dynamic Chart

 

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 09 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials