VBA to Make Check Box Entry
For the most part, I think that the controls from the Forms toolbar are easier
to work with:
Option Explicit
Sub testme()
With Worksheets("Sheet1")
If .Range("A1").Value = 45 Then
.checkboxes("Check box 1").value = xlon
Else
.checkboxes("Check box 1").value = xloff
End If
End With
End Sub
You can actually do it in one line:
with worksheets("sheet1")
.checkboxes("Check box 1").value = cbool(.range("a1").value = 45)
end with
but sometimes seeing the if/then/else makes things easier to understand.
Ken Hudson wrote:
Hi Dave,
Well, I replied too quickly. This workbook was inherited and I thought the
check boxes were created using the Tool Box tool bar. In fact, they were
created using the Forms tool bar.
When I right click on one check box on the form, I see that it is named
Check Box 1.
But I haven't been able to figure out how to get a check mark in it with VBA.
What is the way to reference a check box form in my VBA?
TIA.
--
Ken Hudson
"Dave Peterson" wrote:
Option Explicit
Sub testme()
With Worksheets("Sheet1")
If .Range("A1").Value = 45 Then
.CheckBox1.Value = True
Else
.CheckBox1.Value = False
End If
End With
End Sub
You'll have to know the name of that checkbox in A2. For me, it was named
Checkbox1.
Ken Hudson wrote:
I have a check box on a worksheet that was set up using the Toolbox toolbar.
As part of a VBA routine I want to put a check into that box as part of a
looping routine.
If Range("A1")=45 then
.....code here to put a check into A2
End If
Record a macro wasn't any help.
What is the code to do this, please?
TIA.
--
Ken Hudson
--
Dave Peterson
--
Dave Peterson
|