Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Check boxes not working

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Check boxes not working


Hello Pflugs,

The problem is there are 2 types of Check Boxes in Excel and both ar
accessible through VBA. They are the Forms Toolbar Controls and th
Control Toolbox Controls.

The Forms Toolbar Controls are available from Excel by checking "Forms
under Toolbars. Control Toolbox Controls belong to VBA and are accesse
from Excel by typing ALT + F11 to bring up the Visual Basic Editor o
by selecting the VBA Toolbar under Toolbars.

Your code sample is written for Control Toolbox Controls not Form
Toolbar Controls. Forms Toolbox check boxes are flat, and Contro
ToolBox check boxes are 3D. The name 'checkbox1" is a VBA referenc
name while "Check Box 5" is clearly a Forms Toolbar reference.

Unless I know which type of check box you are using, correcting th
code would difficult, especially if you have mixed the 2 types of chec
boxes.

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48000

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check boxes not working

Looks like you have checkboxes form the forms toolbar. I will assume the
names in your array are correct. It you get an error, that is the first
place to look.

Sub CheckBox1_Click()

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

Dim cost As Long
cost = 0

For Each box In mycheckboxes
If Activesheet.CheckBoxes(box).Value = xlOn Then
cost = cost + 1
End If
Next

Range("j7").Value = cost

End Sub

--
Regards,
Tom Ogilvy

"Pflugs" wrote in message
...
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default Check boxes not working

Wow, I guess that must have been my mistake. I didn't know there were two
types of check boxes. Tom, the code you sent me worked perfectly. This will
enable me to set auto-updating tally sheets for my friend's business.

Am I able to make arrays of all buttons and shapes (i.e. radio buttons) and
perform this same type of check on them, too? How do I know what name to
call them (i.e. CheckBoxes, OptionButtons, others are...)?

Thanks to all,

Pflugs

"Tom Ogilvy" wrote:

Looks like you have checkboxes form the forms toolbar. I will assume the
names in your array are correct. It you get an error, that is the first
place to look.

Sub CheckBox1_Click()

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

Dim cost As Long
cost = 0

For Each box In mycheckboxes
If Activesheet.CheckBoxes(box).Value = xlOn Then
cost = cost + 1
End If
Next

Range("j7").Value = cost

End Sub

--
Regards,
Tom Ogilvy

"Pflugs" wrote in message
...
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.




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
Copy and move check box (check boxes) with new cell link? Marty Excel Worksheet Functions 1 January 20th 10 07:43 PM
How do I increase the size of check in check boxes Adams, Les Excel Discussion (Misc queries) 0 September 19th 06 02:35 PM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
How do i create a value for check boxes or option boxes Tim wr Excel Discussion (Misc queries) 1 February 9th 06 10:29 PM
Check Box influencing other Check Boxes iwrk4dedpr[_2_] Excel Programming 0 May 20th 04 12:55 AM


All times are GMT +1. The time now is 03:38 PM.

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

About Us

"It's about Microsoft Excel"