VBA Userform : Combobox for Chart Type Selection

sachinns

Board Regular
Joined
Jun 21, 2019
Messages
52
Hi Friends,

I have a Userform with a combobox "cmbchart" and i have a sheet with some charts , "Charts".

In the comboBox there should be 3 Chart type listed, Column Chart , Bar Chart, Line Chart . Based on the user selection my chart in "Charts" sheet should be changed (Column,Bar,Line Chart).

Can someone please help me to create code for this .

Thanks in Advance.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Code:
Private Sub cmbChart_Change()
    Dim cType As Variant
    
    Select Case cmbChart.Value
        Case "Column":  cType = xlColumnClustered
        Case "Bar":     cType = xlBarClustered
        Case "Line":    cType = xlLine
    End Select
[COLOR=#006400]'change chart type[/COLOR]
    Sheets("Charts").ChartObjects("[COLOR=#ff0000]Sales by Month[/COLOR]").Activate
    ActiveChart.ChartType = cType
End Sub
Code:
Private Sub UserForm_Initialize()
[COLOR=#006400]'combobox options[/COLOR]
    Dim a As Variant
    For Each a In Array("Column", "Bar", "Line")
        cmbChart.AddItem a
    Next a
End Sub

Amend name of chart

You may find this link useful https://docs.microsoft.com/en-us/office/vba/api/excel.xlcharttype
 
Last edited:
Upvote 0
Thanks for the code. Can you help to edit this code.

I have a ComboBox called "cmbSelChartAttr" . Assume the values in the comobobox as 1,2,3. So if i select 1 then it will create a pivot table in the existing sheet called "1" and it will create a chart in it.
And if i select 2 then it will create a pivot table in the existing sheet called "2" and it will create a chart in it.

So basically the chart name will be "cmbSelChartAttr.Value" ( I Guess ).
So please help me to change the code for it.
 
Upvote 0
I suggest you start a new thread for your new question
 
Upvote 0
I think you didnt understand what i explained. Is it Brother ?

If u know please explain here or if you want me to start new thread . i will do it.
 
Upvote 0
The question you asked in post#1 has been answered

This thread has title Combobox for Chart Type Selection
The question you asked in post#3 ...
- is not reflected in the thread title
- refers to a combobox cmbSelChartAttr (not in post#1)
- asks for code to use selected value in that combobox to create a pivot table ( not in post#1 )
- from pivot table create a pivot chart needs ( not in post#1 )

I suggest you start a new thread for your new question
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

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