I want to write a macro that will create a checkbox in
a cell that meets certain conditions when I click a command button on the top of a column. For example, if the cell's value falls between 1 and -1 in the Q column, the same Q column in which the command button lies, then a macro would generate a checkbox once the Q command button was clicked by the user. I have sample code that works as a macro only when I activate a cell that meets the <1 and >-1 conditions. Ideally, I want the macro to create a checkbox when the user clicks a command button, even if those cells who meet the <1 and >-1 conditions aren't activated by the user. Thanks for any help. Here is my code so far:
a cell that meets certain conditions when I click a command button on the top of a column. For example, if the cell's value falls between 1 and -1 in the Q column, the same Q column in which the command button lies, then a macro would generate a checkbox once the Q command button was clicked by the user. I have sample code that works as a macro only when I activate a cell that meets the <1 and >-1 conditions. Ideally, I want the macro to create a checkbox when the user clicks a command button, even if those cells who meet the <1 and >-1 conditions aren't activated by the user. Thanks for any help. Here is my code so far:
Code:
Sub Mycheckbox2()
Dim objCBox As Object, c As Object
For Each c In Selection
If (c.Value <= 1 And c.Value >= -1) Then
c.Select
Set objCBox = ActiveSheet.CheckBoxes.Add _
(Left:=ActiveCell.Left, Top:=ActiveCell.Top, _
Width:=20, Height:=ActiveCell.Height)
End If
Next c
End Sub