tick box, how to set up

G

Guest

Hi can anyone explain (if possible) how to set up a tick box?

I would like to left cliick on the mouse in a cell (to put tick in) and then
use this tick in a IF statement on another.

Thnaks again Matt
 
B

Biff

Hi!

Here's some code by Bob Phillips and tweaked by Dave Peterson that does what
you want:

This procedure let's you click on a cell in a range (defined in the code)
and places a "checkmark" in
that cell.


Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myHeight As Double
Application.EnableEvents = False
On Error GoTo sub_exit
If Not Intersect(Target, Range("A1:A100")) Is Nothing Then
With Target
If .Value = "a" Then
.Value = ""
Else
myHeight = .EntireRow.RowHeight
.Value = "a"
.Font.Name = "Marlett"
.EntireRow.RowHeight = myHeight
End If
End With
End If
sub_exit:
Application.EnableEvents = True
End Sub



This is sheet code.
Right click the sheet tab and paste into the window that opens.

Then, to use the checkmark in an IF formula you simply need to test the cell
to see if it's empty or not.

Biff
 
B

Biff

Slight typo:
This is sheet code.
Right click the sheet tab and paste into the window that opens.

Should be:

Right click the sheet tab and select View Code. Then paste the code into the
window that opens.

Biff
 
G

Guest

Thanks I think? Which section of code refers to "tick box" location and once
I have pasted into sheet tab do I just close the window or save somehow?

Sorry but I 'm fairly new to excel and probably in way to deep thanks for
your help
Matt
 
B

Biff

Which section of code refers to "tick box" location

This line:

If Not Intersect(Target, Range("A1:A100")) Is Nothing Then

Just change "A1:A100" to whatever range you want.
I have pasted into sheet tab do I just close the window or save somehow?

After you paste the code you just close the VBE (click the "X")

Now, when you select a cell in the defined range a checkmark will appear.
Select that cell again and the checkmark will be removed.

To use that in an IF formula you might do something like this (based on the
cell having the checkmark):

=IF(LEN(A1),do_something,do_something_else)

Biff
 
G

Guest

EXCELLENT i GOT IT WORKING IN COLUMN N BUT WOULD LIKE TO NARROW THAT DOWN TO
N11-N14.
CAN NARROW DOWN TO N14 bUT N1-10 CAN STILL BE TICKED
(opps sorry about caps)

Also is it possable to allow only one tick at a time

Thanks So far keep it coming
Matt
 
G

Guest

Ok was being silly have narrowed the range and all is fine, would still like
a way to only tick one box at a time though.
thanks
 
B

Biff

would still like a way to only tick one box at a time though.

Ok, that greatly complicates things!

If that is your goal, to only be able to select one "checkbox" (cell with a
tick mark) in the range N11:N14, then I would use option buttons. Only one
option button can be selected at any time. To do this is completely
different from what you have done so far.

The first thing you would want to do is to delete that sheet code.

Right click the sheet tab and select View Code.
In the VBE, goto Edit>Select All
Then Edit>Clear
Then close the VBE

Now, setup the option buttons:

Back in the Excel worksheet:

Right click any toolbar
Select Forms
The Forms toolbar should appear
The option button is the one with the black dot in the middle of a "circle"
Click on that then move your cursor to cell N11
Left click and the option button is "dropped" in that location
Now, adjust the size and placement to get it exactly where you want it

Repeat the process for cells N12, N13 and N14.

Now, if you want to use the status of which option button is selected as a
condition in a formula:

You have to link the option buttons to a cell:

Right click any option button
Select Format Control
In the Cell Link box enter a cell location. Whenever an option button is
selected, the linked cell will tell you which button is selected. It will
display the number of which button is selected.

Then you can base your formula on the value of that linked cell.

If you get "lost" and would like me to do this for you just let me know how
to contact you.

Biff
 
G

Guest

All sorted ou tnow thanks for the help!

One Last Question

I wish to Protect My work as it has taken a lot of effort to get it just
right.
Over the 2 padges of my spread sheet there is only maybe 12 cell that have
veriable data (i.e user entry)

How can I protect all but these cells including the option buttons?

Also it is possable to disable the save option? on just this document???

Many thanks agian Matt
 
B

Biff

Hi!

If you used the option buttons:

Right click each button
Select Format Control
Protection tab
Make sure Locked is selected

Now, to protect the worksheet:

Select the entire sheet
Goto Format>Cells
Protection tab
Make sure Locked is selected
OK

Now, select the cells that you want the users to be able to enter data in
*AND* the linked cell for the option buttons.
Goto Format>Cells
Protection tab
Uncheck Locked
OK

Goto Tools>Protection>Protect Sheet

Depending on which version of Excel you are using, there will be various
options for setting protection. Choose the ones you want.
Also it is possable to disable the save option? on just this document???

That would require more VBA programming. I don't know how to do that
specifically so you should ask that question in a new post.

Biff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top