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
Download Sample File: