Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If/then/else code for check boxes in Excel

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi,

I'm trying to code check boxes in Excel to assign one value if they're checked and another if they are not. Here's what I got:

If Worksheets("Sheet1").CheckBoxes(1) = True Then
M = 1
Else
M = 0
If Worksheets("Sheet1").CheckBoxes(2) = True Then
T = 1
Else
T = 0

don't know where the problem is, but Excel doesn't like the code and goes to the "else" part whether it's true or not.

Help!
 
This works. I set it as an OnClick for a button of the sheet, and my check boxes are named CheckBox1 and CheckBox2.

It returns the proper values to cells A1 and A2.

Sub stuff()
Dim M As Integer
Dim T As Integer

If (Worksheets("Sheet1").CheckBox1 = True) Then
M = 1
Else
M = 0
End If
If (Worksheets("Sheet1").CheckBox2 = True) Then
T = 1
Else
T = 0
End If

Range("a1").Select
ActiveCell = M
Range("a2").Select
ActiveCell = T

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top