Check box Code

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15
I need a basic code for checkbox. On a form, when I create a checkbox, I'd like it to add (ex: +1 or -2, depending on the box) to a cell on the same sheet when checked, and add nothing when not checked. How to do this?
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,909
Use a check box from the Forms menu.
Right click on the box and use Format Control to link it to cell A1.

Then =B1 + IF(A1, 2, 0) will return B1 plus either 2 or 0 depending on if the checkbox is checked.
 

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15
Perhaps I did this wrong. I placed the checkbox in Cell I8 and linked it to cell G81. I then entered the formula = I8 + (G81,1,0). Now when I check the box "TRUE" appears in G81 and when unchecked "FALSE". I wanted it to add numbers not show whether the box was actually checked. What am I doing wrong.
 

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15
Also, for some reason when I check one box all the others on the page check as well
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,909

ADVERTISEMENT

"I wanted it to add numbers", which numbers?

The formula =IF(G81,1,0) will return either 2 or 0 depending on if the checkbox is checked.

So, = A1 + IF(G81,1,0) will add either 1 or 0 to the value in A1.

Hence the question "Which numbers?"
The IF / checkbox part is done (unless you want to change 1,0 to 1,-2 which the OP implies)
All that's left is specifiying the other numbers.

(BTW, the checkbox is not in I8. It may be covering I8, but its not in the cell. Nor is it interfering with something being in the cell, beyond the issues of a)seeing what is in I8 and b)selecting I8 without clicking the checkbox. The location of a control on the sheet does not create any relationship between a cell and that control.)

I can't think of why all the checkboxes are reacting as one, unless all of them are linked to the same cell.
 

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15
I'm new so sorry if these are dumb questions. The checkbox's are positioned over several cells in one column (one over each cell). What I'd like is to create a formula/code that when one box is checked, different numbers (+1, -2 or +3) is added to the sum of G81, G82, or G83. I linked each checkbox to G81, G82 or G83 with the formula in the "cell" reading something like =if(G81,2,0). Am I supposed to link the checkbox to the cell underneath it or to the cell I want the number added to?
 

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15

ADVERTISEMENT

Also, the formula =I8 + if (G81,2,0), do I put that in the cell the checkbox is on, the place I want the number to go, or somewhere else?
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,909
Your check boxes are linked to G81:G83, the only thing that they can hold is the True/False determined by the state of the checkbox.

When CheckBox1 (linked to G81) is checked, what number do you want added to what other number?
When its not checked, what number should be added to that other number?

What cell is that other number stored in?
 

hyeflying

New Member
Joined
Oct 30, 2009
Messages
15
THe Idea is that when each box is checked, some will be and some won't, that it adds a specifically assigned number to either box G81, G82, or G83. The check boxes are adjacent to questions on a form and in column J (One per each cell in the column all the way to J40). The form is divided into 3 sections. The first section needs to be totaled in Column G81, second in G82, etc. I do not want the number to appear anywhere else (if possible) other than being added to the G81, G82, etc. What do you think?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,606
Messages
5,597,134
Members
414,128
Latest member
Jorglo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top