chart to form image

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

I would like to know how to make a form image on userfrom1 into a chart, being chart1.

I have tried
Code:
Private Sub Image1_Click()
Image1 = ActiveSheet.ChartObjects("Chart 2")
End Sub

Can anyone help me with this?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I found some code on this site, http://j-walk.com/ss/excel/tips/tip66.htm that I have adapted to the following:
Code:
Private Sub CommandButton1_Click()
Dim MyRegion As String
Dim i As Integer
Dim P_count As Integer
Dim q As Integer
Dim P_Loop As Integer
Dim x As Integer
Application.ScreenUpdating = False
P_count = ActiveSheet.PivotTables.Count
i = 1
Range("A2").Value = ListBox1.Value
MyRegion = Range("A2").Text
ProgressBar1.Visible = True
q = 0
x = 1
P_Loop = P_count * Sheets("Report").PivotTables("PivotTable" & i).PivotFields("Client Region").PivotItems.Count
Do
    With Sheets("Report").PivotTables("PivotTable" & i).PivotFields("Client Region")
        .PivotItems(MyRegion).Visible = True
        For Each Pi In .PivotItems
           If Pi.Name <> MyRegion Then Pi.Visible = False
           q = x / P_Loop * 100
           ProgressBar1.Value = q
           Application.StatusBar = q & "% Complete"
           x = x + 1
         Next Pi
    End With
    i = i + 1
Loop Until i = P_count + 1
Application.StatusBar = ""
Application.ScreenUpdating = True
Unload Me
'Range("A2").Value = "The following infomation of for " & MyRegion
'Range("A2").Speak
'MsgBox ("The following infomation is for " & MyRegion)
End Sub

Private Sub CommandButton2_Click()
Dim CurrentChart As Chart
Dim fname As String
    Set CurrentChart = Sheets("Report").ChartObjects(ComboBox1.Value).Chart
    fname = ThisWorkbook.Path & "\temp.GIF"
    CurrentChart.Export Filename:=fname, FilterName:="GIF"
    Image1.Picture = LoadPicture(fname)
End Sub

Private Sub UserForm_Initialize()
With ListBox1
    .AddItem "Central"
    .AddItem "Eastern Cape"
    .AddItem "Kwa-Zulu Natal"
    .AddItem "Limpopo"
    .AddItem "Mpumalanga"
    .AddItem "Northern Gauteng"
    .AddItem "Southern Gauteng"
    .AddItem "Western Cape"
End With
With ComboBox1
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
    .AddItem "7"
    .AddItem "8"
End With
End Sub

However, all my charts are not hte same size, I am looking for some code that will auto fit the chart size to the image size when it is loading up the temp image.

Please can someone assist.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top