D
davidm
I have a chart loaded onto a Userform and am looking for a way to fi
multiple chart options via option buttons. To illustrate, catering fo
2 options, I attempted something like the codes below which failed wit
Type mismatch error. (The variable CharttNme is declared global a
module level).
What am I doing wrong?
David.
The codes:
Dim CharttNme
Private Sub OptionButton1_Click()
Call CharttType
End Sub
Private Sub OptionButton2_Click()
Call CharttType
End Sub
Private Sub CharttType()
If OptionButton1.Value = True Then
chartNme = xlScatterSmooth
ElseIf OptionButton2.Value = True Then
chartNme = xlColumnClustered
End
End If
Call GraphTables
End Sub
Private Sub GraphTables()
Charts.Add
ActiveChart.ChartType = chartNme *'Type mismatch Error on this line
*ActiveChart.SetSourceData Source:=Sheets("Data").Range("A1:C8")
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Data"
With ActiveChart
.HasTitle = True
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).HasTitle = True
End With
Set ObChart = Sheets("Data").ChartObjects(1).Chart
CurrentChart.ChartType = chartNme
' Save chart as GIF
fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
ObChart.Export FileName:=fname, FilterName:="GIF"
' Show the chart
Image1.Picture = LoadPicture(fname)
Kill fname
End Sub
Private Sub UserForm_Initialize()
OptionButton1_Click
End Su
multiple chart options via option buttons. To illustrate, catering fo
2 options, I attempted something like the codes below which failed wit
Type mismatch error. (The variable CharttNme is declared global a
module level).
What am I doing wrong?
David.
The codes:
Dim CharttNme
Private Sub OptionButton1_Click()
Call CharttType
End Sub
Private Sub OptionButton2_Click()
Call CharttType
End Sub
Private Sub CharttType()
If OptionButton1.Value = True Then
chartNme = xlScatterSmooth
ElseIf OptionButton2.Value = True Then
chartNme = xlColumnClustered
End
End If
Call GraphTables
End Sub
Private Sub GraphTables()
Charts.Add
ActiveChart.ChartType = chartNme *'Type mismatch Error on this line
*ActiveChart.SetSourceData Source:=Sheets("Data").Range("A1:C8")
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Data"
With ActiveChart
.HasTitle = True
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).HasTitle = True
End With
Set ObChart = Sheets("Data").ChartObjects(1).Chart
CurrentChart.ChartType = chartNme
' Save chart as GIF
fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
ObChart.Export FileName:=fname, FilterName:="GIF"
' Show the chart
Image1.Picture = LoadPicture(fname)
Kill fname
End Sub
Private Sub UserForm_Initialize()
OptionButton1_Click
End Su