Highlight row based on checkbox with and without VBA code

santaclaus

New Member
Joined
Aug 1, 2013
Messages
3
Hi,

I've created excel file with old movies (from TSPDT site) and I've added checkbox column. I would like the row from cell A to cell H to highlight green if the checkbox is checked, and to highlight red if it's unchecked.

I've tried rightclick checkbox, then format control, and then link the checkbox with other cell to return true or false and base on that of course I can use conditional formatting. But I would have to do this cell by cell (macro didn't work, copy-paste also didn't work), I have 1000 rows, so maybe there is another way. I've also copied VBA codes from internet - no luck:(

Could you please advise how to highlight cells from A to H based on checkbox status - without VBA code, and second option - using VBA code.

I will be very grateful for your help (it will be easier for me to see which movies I should watch;))

Many thanks,
Santa :stickouttounge:
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
So without vba which would be the easier way to do it... I would do something like this:

First, you will have to link the checkboxes with a cell so that it will produce a usable value to check against... Then we can use conditional formats.

Select your entire range, and click on Conditional Formats > New Rule > Formula and use something along the lines of:

Code:
=IF($J2=TRUE,TRUE,FALSE)

Then just format that cells, how you see fit, you can use both TRUE and FALSE to do both red and green... I hope this helps.

The reason I would stay away from VBA is because you would need to do a check for each checkbox... just easier to do it this way..

(Sorry for the poor quality of my gif, system is acting crazy today)

Excel_Checkbox.gif
 
Upvote 0
Many thanks for your answer, I have one more question.

What is very important for me - could you please write is there a way to do this: First, you will have to link the checkboxes with a cell so that it will produce a usable value to check against in other way than doing it cell by cell (I guess it's impossible to copy down - it won't work).

Best,
Santa


 
Upvote 0
To add checkboxes and the linked cells, try this one. It will create checkboxes in A1 through A10 and link to cells in Column F. To change the linked cell, change 5 in the marked line to whatever you need.

Code:
Sub AddCheckBox()
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("A1:A10")
  With ActiveSheet.CheckBoxes.Add(cell.Left, _
     cell.Top, cell.Width = 15, cell.Height = 12)
     .LinkedCell = cell.Offset(, 5).Address(External:=False) 'This adds the True/False into ColumnF.  Modify as needed
     .Interior.ColorIndex = xlNone
     .Caption = ""
    End With
Next

With Range("A1:A10")
.Rows.RowHeight = 16
End With

Range("A1").EntireColumn.Select
    Selection.ColumnWidth = 5#
Range("B1").Select
Application.ScreenUpdating = True

End Sub
 
Upvote 0
So without vba which would be the easier way to do it... I would do something like this:

First, you will have to link the checkboxes with a cell so that it will produce a usable value to check against... Then we can use conditional formats.

Select your entire range, and click on Conditional Formats > New Rule > Formula and use something along the lines of:

Code:
=IF($J2=TRUE,TRUE,FALSE)

Then just format that cells, how you see fit, you can use both TRUE and FALSE to do both red and green... I hope this helps.

The reason I would stay away from VBA is because you would need to do a check for each checkbox... just easier to do it this way..

(Sorry for the poor quality of my gif, system is acting crazy today)

Excel_Checkbox.gif

Hello, Thank you for the guidance, I am a new excel user and followed your steps and I am having one issue.

I need a large number of check boxes and if I drag them to multiply them they end up working for just one row.

1. I create a check box and enter the formula as you have shown.

2. I drag them to the bottom of the list (or double click on the plus sign)

3. issue: if i click on any check box they end up turning the first row green (i.e. all checkboxes are linked to only the first True/False cell)

hope I am getting my point across.

Regards

QH
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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