How to populate cell contents based on ActiveX checkbox?

Ayugma

New Member
Joined
Nov 20, 2020
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Hi all, how would I populate a specific cell when a checkbox is checked? I tried the code below, but it doesnt change the cell value automatically. Any help would be appreciated.
VBA Code:
Private Sub CommandButton9_Click()
If CheckBox1.Value = True Then
    Range("A109").Value = "ZJ2"
ElseIf CheckBox1.Value = False Then
    Range("A109").ClearContents
    If CheckBox2.Value = True Then
    Range("A109").Value = "ZJ3"
ElseIf CheckBox2.Value = False Then
    Range("A109").ClearContents
End If
End If

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Do you mean you want it to work when you click the checkbox?
 
Upvote 0
How about
VBA Code:
Private Sub CheckBox1_Click()
   Range("A109").Value = IIf(Me.CheckBox1, "ZJ2", "")
End Sub
& the same for the other checkbox
 
Upvote 0
Solution
How about
VBA Code:
Private Sub CheckBox1_Click()
   Range("A109").Value = IIf(Me.CheckBox1, "ZJ2", "")
End Sub
& the same for the other checkbox
Could you please explain what llf is? I haven't seen that yet.
 
Upvote 0
You already have a command button, but you said you wanted it to happen when the check box is clicked. :unsure:
 
Upvote 0
You already have a command button, but you said you wanted it to happen when the check box is clicked. :unsure:
I am so bad at explaining things lol.

Okay so at the start I would have the option for a checkbox. When I hit the command button it would check if the checkbox has been clicked or not and display the results as well.
 
Upvote 0
In that case what is wrong with your code?
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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