![]() |
Checkbox procedures
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 |
Checkbox procedures
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 -- Casey ------------------------------------------------------------------------ Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545 View this thread: http://www.excelforum.com/showthread...hreadid=572416 |
Checkbox procedures
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 rbbbbeee wrote: 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 -- Dave Peterson |
Checkbox procedures
Thanks Casey!
"Casey" wrote: 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 -- Casey ------------------------------------------------------------------------ Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545 View this thread: http://www.excelforum.com/showthread...hreadid=572416 |
Checkbox procedures
Thanks Dave! I believe that I will just link to another cell as you
suggested. Much easier. "Dave Peterson" wrote: 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 rbbbbeee wrote: 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 -- Dave Peterson |
All times are GMT +1. The time now is 12:46 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com