views:

34

answers:

2

I have a checkbox on sheet1 (there are about 7 sheets total). If the checkbox is selected (true), I want it to say "Approved" in cell M9. If the checkbox is not selected (false), I want it to say "Denied" in the textbox.

Do I need to create a macro for that?

If I want it to display the same text in cell M5 of sheet2, how would I put it all together?

+2  A: 

You can link the status of a checkbox to a cell (right-click, format control, cell link on the control tab), this means you can then refer to that cell in any other sheet or cell.

Remou
Thanks, but I have no clue what type of code I would need for that. Any suggestions?
Daniel
There is no code, just formulas: =If(a9, "a9 is true","Denied")Where are you having problems?
Remou
Or even SheetX!a9
Remou
Don't you mean, =If checkbox1.value = true, "Denied"Would that work?
Daniel
But I want to put it in my code, so how do I do that?
Daniel
No, I do not mean checkbox1.value. And, no, it would not work. You need to link the checkbox to a cell, as described. You say you wish to put text in a cell based on a checkbox on sheet1. Why do you now wish to use code? Please update your question to show your new requirements.
Remou
The easiest way is fine. How do I link the checkbox to a cell?
Daniel
I describe it in my answer above. Right-click and choose Format Control, on the Control tab, fill a cell reference into Cell Link.
Remou
Actually it has to apply on the click of a button, so linking wouldn't work.I'm going to have one checkbox on each sheet, so linking would sometimes display something other than what I want.
Daniel
You understand that the linked cell will just give you a convenient way to refer to a checkbox in a worksheet without using code? The value of the linked cell will either be True or False, depending on whether the user has checked the box or not. You can then refer to this cell in any other cell or formula. For example, =IF(A9=TRUE, "Accepted","Denied")
Remou
What is this button to which you refer?
Remou
It's a button that runs other steps of the program. The code above works great for my purposes.
Daniel
You need to rephrase your question, because, at the moment, it asks whether you need a macro, which you don't, for a checkbox, so it should be on superuser.
Remou
+1  A: 

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Range("M9").Value = "Approved"
Else
Range("M9").Value = "Denied"
Sheets("Sheet2").Range("M5").Value = "Denied"
End If
End Sub

krusaint
Are you not thinking if a user form? The above code would need to be added to the checkbox on sheet1, surely it is easier to skip the code and simply link a cell?
Remou
This works great. Linking a cell would eliminate code, which would be a plus, but I don't know how to do it.
Daniel