Problem with disabling ComboBox

Whistler

Board Regular
Joined
Jul 14, 2011
Messages
61
Hi, I have a combo box with name "DropShift" and Checkbox with name "CheckBoxTrend". When the Check box is selected a chart type changing, everything works correectly. But I would like to add that when Check box is selected ComboBox is disabled. But I'm getting Run time error "object required"

Code:
Sub CheckBoxTrend_Change()
Dim ws As Worksheet
Set ws = Worksheets("Data")
Dim ws2 As Worksheet
Set ws2 = Worksheets("Dashboard")


If ws2.CheckBoxes("CheckBoxTrend").Value = xlOff Then
ShiftDrop.Enabled = False
ws2.ChartObjects("Chart 17").Activate
ActiveChart.ChartType = xlColumnStacked
With ws.PivotTables("PivotTrend").PivotFields("Shift")
        .Orientation = xlColumnField
        .Position = 1
    End With
End If

If ws2.CheckBoxes("CheckBoxTrend").Value = xlOn Then
ShiftDrop.Enabled = True
ws2.ChartObjects("Chart 17").Activate
ActiveChart.ChartType = xlColumnClustered
With ws.PivotTables("PivotTrend").PivotFields("Shift")
        .Orientation = xlPageField
        .Position = 1
    End With
ActiveChart.SeriesCollection(1).Trendlines.Add
    With ActiveChart.SeriesCollection(1).Trendlines(1)
    .Border.ColorIndex = 3
    .Border.Weight = xlMedium
    .Border.LineStyle = xlContinuous
    End With

End If
End Sub

Any help much appreciated!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi

In your question you mentioned that the combobox is called "DropShift" but in your code you refer to "ShiftDrop". Is it possible that you have just used the incorrect combobox name? (I am assuming that you do not have Option Explicit in your module as this would have been picked up during compilation).

HTH
DK
 
Upvote 0
Thanks for the replay,

I made mistake when I was writing last post should be ShiftDrop, both name are the same in the code and in excel. Any through?
 
Upvote 0
And I completely don't know what is Option Explicit and how this can help me with finding faults like this.
 
Upvote 0
I've forgot to mention that both ComboBox and CheckBox are Form Controls not ActiveX, and they are located on the pivotChart.

Any Idea?
 
Upvote 0
I have managed to sort it:cool:

Full solution if anyone interested


Code:
Sub CheckBoxTrend_Click()

Dim ws As Worksheet
Set ws = Worksheets("Data")
Dim ws2 As Worksheet
Set ws2 = Worksheets("Dashboard")


If ws2.CheckBoxes("CheckBoxTrend").Value = xlOff Then
ws2.DropDowns("ShiftDrop").Enabled = False

ws2.ChartObjects("Chart 17").Activate
ActiveChart.ChartType = xlColumnStacked
With ws.PivotTables("PivotTrend").PivotFields("Shift")
        .Orientation = xlColumnField
        .Position = 1
    End With
End If

If ws2.CheckBoxes("CheckBoxTrend").Value = xlOn Then
ws2.DropDowns("ShiftDrop").Enabled = True
ws2.ChartObjects("Chart 17").Activate
ActiveChart.ChartType = xlColumnClustered
With ws.PivotTables("PivotTrend").PivotFields("Shift")
        .Orientation = xlPageField
        .Position = 1
    End With
ActiveChart.SeriesCollection(1).Trendlines.Add
    With ActiveChart.SeriesCollection(1).Trendlines(1)
    .Border.ColorIndex = 3
    .Border.Weight = xlMedium
    .Border.LineStyle = xlContinuous
    End With

End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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