UserForm Checkbox

G1032

New Member
Joined
Feb 1, 2019
Messages
15
Hi folks

I have a simple UserForm which has 3 checkboxes.
Checkboxes labelled "Good" , "Average" and "Bad"
When "Good" is checked, the value "1" is entered into a cell. If "Average" is checked then the value "0.5" is entered and "0" is entered when "Bad" is checked.

The problem is this......I need all 3 checkboxes to be clear when I open up the UserForm. But when I add in a line of code to clear the checkbox it also enters the 1 or 0.5 or 0.

How do I check a box, get the data entered into the cell I want, and then uncheck that same box without writing any further data?
Thanks

Code:
Private Sub CheckBox14_Click()With Sheets("RawData").Select
Range("E65536").End(xlUp).Offset(1, 0).Select
ActiveCell.Value = "1"
Sheets("Home").Select
Range("A1").Select
End With
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi & welcome to MrExcel.
try using an AfterUpdate event instead
Code:
Private Sub CheckBox14_AfterUpdate()
 
Upvote 0
Or You could do this

Code:
Private Sub TextBox14_Change()
    Sheets("RawData").Range("E65536").End(xlUp).Offset(1, 0).Value = CheckBoxTextValue
End Sub

Private Sub TextBox15_Change()
    Sheets("RawData").Range("E65536").End(xlUp).Offset(1, 0).Value = CheckBoxTextValue
End Sub

Private Sub TextBox16_Change()
    Sheets("RawData").Range("E65536").End(xlUp).Offset(1, 0).Value = CheckBoxTextValue
End Sub

Function CheckBoxTextValue() as String
    If CheckBox14.Value Then
        CheckBoxTextValue = "1"
    ElseIf CheckBox15.Value Then
        CheckBoxTextValue = ".5"
    ElseIf CheckBox16.Value Then
        CheckBoxTextValue = "0"
    Else
        CheckBoxTextValue = vbNullString
    End If
End Function
 
Upvote 0
Another option:-

Code:
[COLOR="Navy"]Sub[/COLOR] chk(Cb)
[COLOR="Navy"]Dim[/COLOR] cBox [COLOR="Navy"]As[/COLOR] Control, Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Num [COLOR="Navy"]As[/COLOR] Double
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] cBox [COLOR="Navy"]In[/COLOR] Me.Controls
[COLOR="Navy"]If[/COLOR] TypeName(cBox) = "CheckBox" [COLOR="Navy"]Then[/COLOR]
   [COLOR="Navy"]If[/COLOR] Not cBox.Name = Cb.Name [COLOR="Navy"]Then[/COLOR] cBox.Value = False
   [COLOR="Navy"]If[/COLOR] cBox.Name = Cb.Name [COLOR="Navy"]Then[/COLOR]
        Lst = Range("E" & Rows.Count).End(xlUp).Offset(1).Row
              [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Cb.Name
                    [COLOR="Navy"]Case[/COLOR] "CheckBox1": Num = 1
                    [COLOR="Navy"]Case[/COLOR] "CheckBox2": Num = 0.5
                    [COLOR="Navy"]Case[/COLOR] "CheckBox3": Num = 0
                [COLOR="Navy"]End[/COLOR] Select
                Cells(Lst, "E") = Num
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] cBox
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

Private [COLOR="Navy"]Sub[/COLOR] CheckBox1_AfterUpdate()
chk CheckBox1
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]


Private [COLOR="Navy"]Sub[/COLOR] CheckBox2_AfterUpdate()
chk CheckBox2
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

Private [COLOR="Navy"]Sub[/COLOR] CheckBox3_AfterUpdate()
chk CheckBox3
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Thanks folks for your replies
I'll check them out later when I get a chance. Cheers!
 
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top