VBA Formatting to Highlight Text Based on Checkbox

Shelby21

Board Regular
Joined
Nov 21, 2017
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I've got another question regarding the use of checkboxes and highlighting values based on if a box is checked or not.

Looking at the image below, I would like to highlight the number above a checkbox if it is checked.

This one is a bit tricky since the numbers are all inserted text boxes within the same cell as the checkboxes so the vba formula would have to associate each checkbox with its correct text box number above it and then change the fill color to yellow if the box is checked.

Any help would be much appreciated as this is definitely beyond my current capability of vba coding :)

check.PNG
 

Attachments

  • check.PNG
    check.PNG
    16.4 KB · Views: 10

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Are they Form Controls or ActiveX controls?
 
Upvote 0
What about the textboxes?
 
Upvote 0
The text boxes are regular texbox using shape command.

I can change these to ActiveX textboxes though if needed.
 
Upvote 0
Ok, you can use something like for each checkbox
VBA Code:
Private Sub CheckBox1_Click()
   If Me.CheckBox1.Value Then
      Me.Shapes("TextBox 1").Fill.ForeColor.RGB = vbYellow
   Else
      Me.Shapes("TextBox 1").Fill.ForeColor.RGB = vbWhite
   End If
End Sub
 
Upvote 0
Solution
Ok, you can use something like for each checkbox
VBA Code:
Private Sub CheckBox1_Click()
   If Me.CheckBox1.Value Then
      Me.Shapes("TextBox 1").Fill.ForeColor.RGB = vbYellow
   Else
      Me.Shapes("TextBox 1").Fill.ForeColor.RGB = vbWhite
   End If
End Sub
That worked perfectly!

Once I re-assigned all the checkbox and text box numbers to correspond with the correct values it worked exactly as I wanted it to.

Thank you for your help!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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