I have a userform that displays charts from a worksheet, the form has a next and previous option to view each chart, this works fine if all the charts are on the same worksheet. I need to use charts for various worksheets, how can i do this?
My code is:
![]()
Dim ChartNum As Integer Private Sub UserForm_Initialize() ChartNum = 1 UpdateChart End Sub Private Sub PreviousButton_Click() If ChartNum = 1 Then ChartNum = 3 Else ChartNum = ChartNum - 1 UpdateChart End Sub Private Sub NextButton_Click() If ChartNum = 3 Then ChartNum = 1 Else ChartNum = ChartNum + 1 UpdateChart End Sub Private Sub CloseButton_Click() Unload Me End Sub Private Sub UpdateChart() Set CurrentChart = Sheets("SheetName").ChartObjects(ChartNum).Chart CurrentChart.Parent.Width = 725 CurrentChart.Parent.Height = 450 ' Save chart as GIF Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif" CurrentChart.Export FileName:=Fname, FilterName:="GIF" ' Show the chart Image1.Picture = LoadPicture(Fname) End Sub











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks