How to Display Multiple Charts from Excel Worksheet on UserForm

How to Display Multiple Charts from an Excel Worksheet on a UserForm automatically and navigate through the charts. The video below and the accompanying VBA macro code explain how to create ‘GIF’ files from the multiple charts and then place them on the user-form. We can now navigate and view the charts one by one using the navigation command buttons. The ‘close’ button closes the user-form and removes it from memory.

You can view the video on YouTube.

Here’s the complete VBA code to display multiple charts from an Excel worksheet on a user-form:

Dim chartNum As Long

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdNext_Click()
If chartNum = 4 Then
chartNum = 1
Else
chartNum = chartNum + 1
End If

GetChart
End Sub

Private Sub cmdPrevious_Click()
If chartNum = 1 Then
chartNum = 4
Else
chartNum = chartNum – 1
End If
GetChart
End Sub

Private Sub UserForm_Initialize()
chartNum = 1
GetChart

End Sub

Private Sub GetChart()

Set CurrentChart = Sheet1.ChartObjects(chartNum).Chart
CurrentChart.Parent.Width = 500
CurrentChart.Parent.Height = 250

picFileName = ThisWorkbook.Path & “\” & “mychart.gif”
CurrentChart.Export Filename:=picFileName, FilterName:=”GIF”

Image1.Picture = LoadPicture(picFileName)
End Sub

Module1:

Sub displayUserForm()
UserForm1.Show
End Sub

Further Reading:

Displaying a chart on a user-form

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

Leave a Reply

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