Hi All,
Excuse my Novas question, I am a complete rookie when it comes to VBA.
I am currently using the below code to populate the values of checkboxes to enable the ability to add all activated checkboxes. As the sheet contains a lot of checkboxes and not just a single row, the values of the boxes is becoming messy and hard to differentiate between them.
Ideally I would like to have all checkbox values populate to a separate sheet and have the ability to have them grouped based on the rows of the correlating checkboxes on the previous sheet. This would allow me to use the countif (x:x,true) function to total the values.
Currently the code takes all checkboxes values and runs them in a continued column on the same sheet.
I am also open to alternative ways to achieve the same outcome.
Sub LinkChecks()
'Update 20150310
i = 2
For Each cb In ActiveSheet.CheckBoxes
cb.LinkedCell = Cells(i, "B").Address
i = i + 1
Next cb
End Sub
Thank you
Hi Nathan,
Can you please supply your workbook. It'll be easier for me to understand what you are trying to do if I can see the sheet(s).
Regards
Phil
Hi Philip,
Thank you for your response. I have provided the workbook attached. I have added some additional comments into the sheet "Value Locations".
Please let me know if you need further information.
Thank you
Hi Nathan,
You said you were open to alternative approaches so how about this. Rather than using checkboxes, I'm using Worksheet_SelectionChange events to check what cells are being clicked in. If you click into a cell related to a Vehicle/Date the macro fills that cell in with green and places the value 1 into it.
The number is also green so you can't see it. It just looks like a green cell, but because there are numbers in each cell you can use formulas like SUM to count up how many cells are filled in/clicked.
I've created a new sheet called MOTH in the attached workbook. Open it and go into the VBA editor you will see in the Sheet3(MOTH) code module the VBA that does all of this.
I've created 2 named ranges Nov and Dec that refer to the relevant cells for those months. Nov refers to MOTH!$C$3:$AF$7 and Dec refers to MOTH!$C$11:$AF$15.
If you add more months then create a named range for each. You will also need to add code in the event to check for clicks into this new named range. You'll need to add to this line for each new named range.
If Not Intersect(Target, ActiveSheet.Range ("Nov")) Is Nothing Or Not Intersect (Target, ActiveSheet.Range ("Dec")) Is Nothing Then
You can change the cell and font colour to whatever you like.
Let me know if you need to adapt this further.
Useful reading on events:
Workbook and Worksheet Events in VBA
regards
Phil