+ Reply to Thread
Results 1 to 4 of 4

Chart in userform

Hybrid View

intex Chart in userform 03-28-2015, 06:01 PM
Domenic Re: Chart in userform 03-28-2015, 10:00 PM
intex Re: Chart in userform 03-29-2015, 05:54 AM
Domenic Re: Chart in userform 03-29-2015, 10:35 AM
  1. #1
    Forum Contributor
    Join Date
    08-08-2012
    Location
    englang
    MS-Off Ver
    Excel 2010
    Posts
    152

    Chart in userform

    Hi Guys,

    I'm trying to display the chart in userform using the code below which i found on net, but getting an error on red line below stating that the variable not set, any ideas why it is happening?

    Any thoughts are welcome, thanks in advance.

    Private Sub UserForm_Initialize()
    Dim ChartNum As Integer
      ChartNum = 1
        UpdateChart
    End sub
    Private Sub UpdateChart()
    Dim ChartNum As Integer
        Set CurrentChart = Sheets("Data Collection").ChartObjects(ChartNum).Chart
        CurrentChart.Parent.Width = 300
        CurrentChart.Parent.Height = 150
    
    '   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
    Last edited by intex; 03-29-2015 at 05:53 AM.

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Chart in userform

    Try...

    Private Sub UserForm_Initialize()
        UpdateChart
    End Sub
    Private Sub UpdateChart()
    
        Dim Fname As String
        Dim CurrentChart As Chart
        Dim ChartNum As Integer
    
        ChartNum = 1
    
        Set CurrentChart = Sheets("Data Collection").ChartObjects(ChartNum).Chart
    
        CurrentChart.Parent.Width = 300
        CurrentChart.Parent.Height = 150
    
    '   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
    Hope this helps!

  3. #3
    Forum Contributor
    Join Date
    08-08-2012
    Location
    englang
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Chart in userform

    Thanks Domenic, it works perfectly.

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Chart in userform

    You're very welcome!

    Cheers!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Chart on a Userform
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-31-2024, 12:15 PM
  2. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-04-2014, 07:11 AM
  3. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-03-2014, 12:28 PM
  4. Chart in Userform
    By BrianAll in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-22-2013, 01:36 PM
  5. [SOLVED] Chart on a Userform
    By Rocky McKinley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2005, 11:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1