Quantcast
Viewing all articles
Browse latest Browse all 50194

Charting Issues

Hi Everyone,

How can I change my chart in userform from the combobox? I have just two charts I am testing from and can't figure out how to switch from one to the other.

Code:

Dim iChartType As Long


Private Sub UserForm_Activate()
    ComboBox1.ListIndex = 0
'Initialise the selections
cb3D = True
obColumn = True
obBitmap = True
End Sub

Private Sub btnOK_Click()
Unload Me
End Sub

Private Sub cb3D_Click()
Select Case True
Case obColumn
    obColumn_Click
Case obLine
    obLine_Click
Case obArea
    obArea_Click
End Select
End Sub

Private Sub obColumn_Click()
iChartType = IIf(cb3D, xl3DColumn, xlColumnClustered)
UpdateChart
End Sub

Private Sub obLine_Click()
iChartType = IIf(cb3D, xl3DLine, xlLine)
UpdateChart
End Sub

Private Sub obArea_Click()
iChartType = IIf(cb3D, xl3DArea, xlArea)
UpdateChart
End Sub



Private Sub UpdateChart()

Dim oCht As Chart, lPicType As Long
Dim i As Long

finalrow = Cells(Rows.Count, 9).End(xlUp).Row
For i = 1 To finalrow
Set oCht = Sheet1.ChartObjects(i).Chart
Next i


'Do we want a metafile or a bitmap?
'If doing a 1 to 1 copy, xlBitmap will give a 'truer' rendition.
'If scaling the image, xlPicture will give better results

lPicType = IIf(obMetafile, xlPicture, xlBitmap)

'Update the chart type and copy it to the clipboard, as seen on screen
With oCht
    .ChartType = iChartType
    .CopyPicture xlScreen, lPicType, xlScreen
End With

'Paste the picture from the clipboard into our image control
Set imgChtPic.Picture = PastePicture(lPicType)

End Sub


Viewing all articles
Browse latest Browse all 50194