Checkbox procedures

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried several different things and I don't know alot about checkbox
procedures.
This is what I want to do. I have a checkbox in a worksheet lets say at
cell B3. I want the cell at B4 to contain the word "YES" when the checkbox
is ticked and blank when the box is not ticked.
Could someone please write me the code that will do what I am wanting to do,
then I can expand on it as I need to.

Thanks,
Russ
 
Russ,
A disclaimer first, I am not an expert in VBA like some on this site,
but this code works for me.

Private Sub CheckBox1_Click()
Dim i As Boolean
Dim rng1 As Range

Application.DisplayAlerts = False
i = CheckBox1.Value
Set rng1 = Range("$B$4")
If i = True Then
rng1.Value = “YES”
Else
rng1.Value = “”
End If
Application.DisplayAlerts = True

End Sub

HTH
 
How about dropping the code and just using a linked cell and then point at that
linked cell.

I dropped a checkbox from the Forms toolbar onto a worksheet.
I rightclicked on that checkbox and chose format control
Then on the control tab, I added an address for the Cell Link. (I used B3, but
you could use any cell you want.)

Then in B4, I put this formula:
=if(b3=true,"YES","")

And I gave B3 a custom format of:
;;;
(3 semicolons, so I couldn't see the True/False in the worksheet.)

=========
If you really, really want code (I wouldn't!)...

You could assign this macro to the checkbox:

Option Explicit
Sub testme01()

Dim myCBX As CheckBox

Set myCBX = ActiveSheet.CheckBoxes(Application.Caller)

If myCBX.Value = xlOn Then
activesheet.range("B4").value = "YES"
Else
activesheet.range("B4").clearcontents
End If

End Sub
 
Thanks Dave! I believe that I will just link to another cell as you
suggested. Much easier.
 

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

Back
Top