Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Counting checkboxes with a true value

Hello,
I have four checkboxes on a worksheet. I would like to
have a macro that anytime a checkmark is placed in one of
the checkboxes to go through those checkboxes, validate
for their value (true or false), and count the ones that
are true. It then puts that count into a cell on the same
worksheet. I have assigned the same group name to all four
checkboxes.
Can anyone help please?
All suggestions/solutions are greatly appreciated.
TIA.
BR, Antje Crawford
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Counting checkboxes with a true value

Hi Antje,

Something like this should work:

Private Sub chk1_Click()
CalcCount
End Sub

Private Sub chk2_Click()
CalcCount
End Sub

Private Sub chk3_Click()
CalcCount
End Sub

Private Sub chk4_Click()
CalcCount
End Sub

Private Sub CalcCount()
Dim ctl As OLEObject
Dim n As Integer

For Each ctl In OLEObjects
If TypeOf ctl.Object Is MSForms.CheckBox Then
If ctl.Object.Value And _
ctl.Object.GroupName = "Test" Then n = n + 1
End If
Next ctl

Range("A1").Value = n
End Sub

This assumes your GroupName is "Test". Just put this code behind the
worksheet containing the checkboxes (right-click sheet tab | View Code).

Alternatively, you could set the LinkedCell property of each checkbox to a
different cell and count up the TRUE values with a COUNTIF formula. That
would require no VBA code.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Antje Crawford wrote:
Hello,
I have four checkboxes on a worksheet. I would like to
have a macro that anytime a checkmark is placed in one of
the checkboxes to go through those checkboxes, validate
for their value (true or false), and count the ones that
are true. It then puts that count into a cell on the same
worksheet. I have assigned the same group name to all four
checkboxes.
Can anyone help please?
All suggestions/solutions are greatly appreciated.
TIA.
BR, Antje Crawford


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Counting checkboxes with a true value

Jake,
it works like a charm. Thanks alot.
BR,
Antje Crawford
-----Original Message-----
Hi Antje,

Something like this should work:

Private Sub chk1_Click()
CalcCount
End Sub

Private Sub chk2_Click()
CalcCount
End Sub

Private Sub chk3_Click()
CalcCount
End Sub

Private Sub chk4_Click()
CalcCount
End Sub

Private Sub CalcCount()
Dim ctl As OLEObject
Dim n As Integer

For Each ctl In OLEObjects
If TypeOf ctl.Object Is MSForms.CheckBox Then
If ctl.Object.Value And _
ctl.Object.GroupName = "Test" Then n = n

+ 1
End If
Next ctl

Range("A1").Value = n
End Sub

This assumes your GroupName is "Test". Just put this

code behind the
worksheet containing the checkboxes (right-click sheet

tab | View Code).

Alternatively, you could set the LinkedCell property of

each checkbox to a
different cell and count up the TRUE values with a

COUNTIF formula. That
would require no VBA code.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Antje Crawford wrote:
Hello,
I have four checkboxes on a worksheet. I would like to
have a macro that anytime a checkmark is placed in one

of
the checkboxes to go through those checkboxes, validate
for their value (true or false), and count the ones that
are true. It then puts that count into a cell on the

same
worksheet. I have assigned the same group name to all

four
checkboxes.
Can anyone help please?
All suggestions/solutions are greatly appreciated.
TIA.
BR, Antje Crawford


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting TRUE or FALSE Paul Gooch Excel Worksheet Functions 7 August 13th 08 10:31 PM
TRUE/FALSE from checkboxes Phil Davy Excel Discussion (Misc queries) 4 September 27th 07 04:09 PM
Counting the number of checkboxes on a spreadsheet Candice H. Excel Worksheet Functions 6 May 20th 05 05:27 PM
Convert True/False to checkboxes Eric[_7_] Excel Programming 2 September 3rd 03 04:28 PM
Counting checkboxes Shamsul Excel Programming 1 August 11th 03 03:26 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"