VBA Formatting to Highlight Text Based on Checkbox

Shelby21

New Member
Joined
Nov 21, 2017
Messages
30
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: 3

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,638
Office Version
  1. 365
Platform
  1. Windows
Are they Form Controls or ActiveX controls?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,638
Office Version
  1. 365
Platform
  1. Windows
What about the textboxes?
 

Shelby21

New Member
Joined
Nov 21, 2017
Messages
30

ADVERTISEMENT

The text boxes are regular texbox using shape command.

I can change these to ActiveX textboxes though if needed.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,638
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

Shelby21

New Member
Joined
Nov 21, 2017
Messages
30
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!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,638
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,141,818
Messages
5,708,768
Members
421,588
Latest member
Wawie

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
Top