Combine selection from multiple checkboxes

dgregory1979

New Member
Joined
Oct 4, 2017
Messages
1
First, I am new to VBA and this is my very first time posting a question. Please let me know if I should provide additional detail, etc. Here goes… I have a worksheet (built with MS Excel 2013) with a table and graph. There are VBA checkboxes built in so the end user can make a selection to add/remove select groups from the graph (e.g., Group1, Group2, …, Group<n>), which is read directly from the table on the same worksheet. The current setup with the code pasted below works as desired.

However, I need to make a change to accommodate multiple selections and I am unsure how to do so. For example, I need to add/accommodate selections for subgroups within each group (e.g., Subgroup1, Subgroup2, Subgroup3). The “Group” values are currently in Column C in the spreadsheet and the new Subgroup values are in Column D. I am unsure how to update the code for the multiple selections. For example, if the user selects a checkbox for Group1 and Subgroup1, a single row of data will be displayed on the chart. If the user selects a checkbox for both Group1 and Group2 and Subgroup1, two rows will be displayed on the chart. If the user selects a checkbox for both Group1 and Group2 and Subgroup1 and Subgroup2, four rows will be displayed on the chart. Each Group and Subgroup correspond to a row of data in the table. I am unsure where to start to get the multiple selections (i.e., Group and subgroup) to work together. I greatly appreciate any advice. Thanks!

Current VBA code to select rows in table to display in a chart (based on check box)

Sub selectesco(Grp As String)
Dim row As Integer
application.ScreenUpdating = False
wrksht = ActiveSheet.Name
Range("C30:C1000").Select
Selection.Find(What:=Grp, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
row = ActiveCell.row + 1
ActiveSheet.ChartObjects("Chart 1").Activate
With ActiveChart.SeriesCollection.NewSeries
.Values = "='" & wrksht & "'!$F$" & row & ":$Y$" & row & ", '" & wrksht & "'!$AA$" & row & ":$AF$" & row
.Name = "='" & wrksht & "'!$C$" & row - 1
.XValues = "=('" & wrksht & "'!F32:Y33, '" & wrksht & "'!AA32:AF33)"
End With
application.ScreenUpdating = True

End Sub

VBA code for check box

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
selectesco ("Group1")
Else: DeleteSeriesWith_Series_InName ("Group1")
End If

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,990
Messages
6,128,158
Members
449,428
Latest member
d4vew

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