View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
chijanzen chijanzen is offline
external usenet poster
 
Posts: 139
Default Check boxes not working

Hi,Pflugs

Sub CheckBox1_Click()
Dim mycheckboxes As Variant
mycheckboxes = Array("CheckBox1", "Checkbox5", "Checkbox6", "Checkbox7")
Dim cost As Integer
cost = 0
For Each box In Me.Controls
If TypeName(box) = "CheckBox" Then
On Error Resume Next
r = Application.WorksheetFunction.Match(box.Name, mycheckboxes, 0)
If Err = 0 And box Then
cost = cost + 1
End If
End If
Next
Range("j7").Value = cost
End Sub

--
http://www.vba.com.tw/plog/


"Pflugs" wrote:

I am not able to access check boxes through macros. I searched the help
files and this forum, and I know that I am supposed to use something like
"CheckBox1", but it keeps telling me that "Object Required."

Here's my code:

Sub CheckBox1_Click()

Dim mycheckboxes As Variant
mycheckboxes = (Array("checkbox1", "check box 5", "check box 6", "check box
7"))

Dim cost As Integer
cost = 0

For Each box In mycheckboxes
If box.Value = Checked Then
cost = cost + 1
End If
Next

Range("j7").Value = cost

End Sub

Thanks for the advice.