Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Question about checkboxes

The control toolbox toolbar and all its controls were added in xl97.

The controls on the control toolbox have lots and lots of different events and
properties. The controls from the Forms toolbar can't be formatted as many
different ways and have macros assigned to them.

I find that the controls from the Forms toolbar behave more nicely. And if I
don't need all those other properties and events, I'll use them instead of the
control toolbox toolbar controls.



WLMPilot wrote:

Thanks for your help. However, it now brings up a question about something I
did not know existed. I was not aware of the Forms toolbar. What is the
difference between the Forms and Control toolbar and why would one be used
over the other?

Les

"Dave Peterson" wrote:

You can use a single macro if you use checkboxes from the Forms toolbar.

You could use 11 macros that call a single macro that does the real work if you
use checkboxes from the Control toolbox toolbar.

For checkboxes from the Forms toolbar, you could use a macro like this (placed
in a general module):

Option Explicit
Sub testme()
Dim CBX As CheckBox

Set CBX = ActiveSheet.CheckBoxes(Application.Caller)

If CBX.Value = xlOn Then
CBX.TopLeftCell.Offset(0, 1).Value = 16
Else
CBX.TopLeftCell.Offset(0, 1).Value = 8
End If

End Sub

For checkboxes from the Control toolbox toolbar, you could use something like:

Option Explicit
Private Sub CheckBox1_Click()
Call DoTheWork(Me.CheckBox1)
End Sub
Private Sub CheckBox2_Click()
Call DoTheWork(Me.CheckBox2)
End Sub
Private Sub DoTheWork(CBX As MSForms.CheckBox)
If CBX.Value = True Then
CBX.TopLeftCell.Offset(0, 1).Value = 16
Else
CBX.TopLeftCell.Offset(0, 1).Value = 8
End If
End Sub

You'd need 11 of those _click events that call the single DoTheWork subroutine.

And all these procedures would be in the worksheet module (although, the
DoTheWork procedure could live in a General module -- but remove the Private
from the definition).



WLMPilot wrote:

That worked great! Thanks.

I would like to re-ask the question, though. In an effort to help learn VBA
in Excel and different ways to do things, can a single macro be written that
can look at each checkbox, evaluate it (true/false), and place its respectful
value in the appropriate cell? I am thinking it can be down, but somehow the
macro must look at the name of the checkbox and pull out the numeric value,
checkbox1, 2, 3, etc. before making further determinations. I just do not
know how to get the name.

Thanks again for you help?
Les

"Dave Peterson" wrote:

These are checkboxes from the Control toolbox toolbar.

Go into Design Mode
Rightclick on one and choose Properties
Scroll down to Linked cell and type in an address (I'll use A1 for ease of use,
but it can be in a hidden column on the same worksheet or even on a different
(hidden) worksheet).

Then you can use a formula that in B20 of the Pay-Calc worksheet:
=if(a1=true,16,8)
or
=if('Sheet 9999'!a1=true,16,8)

=========
Since you're using checkboxes from the control toolbox, you can't have one
subroutine that does all the work. You could have 11 subroutines that call a
single routine (passing it the information that the common routine would need)
that does all the work.

Or you could use checkboxes from the Forms toolbar and you can assign a single
common macro to each of the checkboxes.

But I don't think I'd use either macro approach. I'd just use the linked cell
and a formula.




WLMPilot wrote:

I do not understand what you mean.

Below is the code that is currently used for each checkbox (with the
checkbox number changed for each):

Private Sub CheckBox11_Click()
If CheckBox11.Value = True Then
Worksheets("Pay-Calc").Cells(20, 2).Value = 16
Else: Worksheets("Pay-Calc").Cells(20, 2).Value = 8
End If
End Sub

Les

"Dave Peterson" wrote:

Why not just change the linked cell to point at that adjacent cell? Then you
don't even have to use code.




WLMPilot wrote:

I have 11 checkboxes (checkbox23-33). Currently, I have a macro per checkbox
that evaluates if box is True/False and then places a value in adjacent cell.

Is there a way to write one macro that will look at each checkbox and do the
same thing?

Thanks,
Les

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
VBA Checkboxes [email protected] Excel Programming 6 April 23rd 08 04:57 PM
Newbie : question on VBA and checkboxes Daniel[_18_] Excel Programming 6 November 1st 07 03:28 PM
question on VBA and Checkboxes - Newbie Daniel[_18_] Excel Programming 5 October 27th 07 01:55 PM
question regaridng checkboxes Monte0682 Excel Programming 1 March 13th 07 10:22 PM
Checkboxes and Other cmk18[_3_] Excel Programming 1 April 5th 04 05:09 AM


All times are GMT +1. The time now is 06:45 PM.

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"