Filtering on cells with checkboxes

quercus

New Member
Joined
Feb 23, 2009
Messages
19
I've found this code which works a treat in adding multiple checkboxes to a selection of cells on a worksheet. The checkboxes are also linked to the cells.

Unfortunately, it doesn't seem to filter as I would expect - it appears to only have 'TRUE'/'Blanks' as options whereas I was expecting to be able to filter with the TRUE/FALSE values. Even with the true/blanks the filter doesn't work.

Is there a work around or should I consider using an alternative to the checkbox? :rolleyes:

Code:
Sub AddCheckBoxes()
On Error Resume Next
Dim c As Range, myRange As Range
Set myRange = Selection
For Each c In myRange.Cells
ActiveSheet.CheckBoxes.Add(c.Left, c.Top, c.Width, c.Height).Select
With Selection
.LinkedCell = c.Address
.Characters.Text = ""
.Name = c.Address
End With
Range(c, c.Offset(, 1)).Select
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=" & c.Address & "=TRUE"
.FormatConditions(1).Interior.ColorIndex = 6
End With
With c
.FormatConditions(1).Font.ColorIndex = 6
.Font.ColorIndex = 2
End With
Next
myRange.Select
End Sub
thanks
Quercus
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi Quercus,

Supposing you have created a check-box in cell A1 you can use in Excel
=IF(A1,"something","other")

Or in VBA

Code:
If Range("A1") Then
        ' do some stuff
Else
        ' do other stuff
End If

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

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