Selecting charttype from macro is not working
Charttype is looking for a number, not a text string.
VBA has some predefined constants, such as xlLine, but xlLine actually holds
the value 4 so when you do
....charttype = xlLine
you are really saying
....charttype = 4
not
....charttype = "xlLine"
Adjust your code to provide the appropriate numeric value.
--
Regards,
Tom Ogilvy
"Shuvro Basu" wrote:
Hi All,
I am trying to specify a chart type from a userform. The chart is
selected by the user in the active sheet and then the macro is run. It
tries to change the chart type to the one selected from the combobox.
When I hardcode the charttype in the macro it works. However when I try
to get value from the combobox text it doesnt. What is wrong? I'm
putting the code below for your reference :
Private Sub CommandButton2_Click()
On Error Resume Next
Dim ct As Integer
Dim chrttype As String
ct = ComboBox1.Value
chrttype = Trim(ListBox1.Value)
'MsgBox chrttype
'On Error Resume Next
If ct = 0 Then
MsgBox "Please select a series value from the list to continue..."
Exit Sub
Else
ActiveChart.SeriesCollection(ct).Select
ActiveChart.SeriesCollection(ct).ChartType = chrttype
ActiveChart.SeriesCollection(ct).Select
End If
CommandButton2.Visible = False
ListBox1.Visible = False
End Sub
|