PDA

View Full Version : Filter by color using checkbox



HugoAvila
08-22-2012, 06:22 PM
i'm brazilian, so sorry for my bad english.:dunno i need a big huge help. i have
an excel file that i want to do something in vba but , after look for day on
the internet trying to find , i didnt.:banghead: i want in VBA do a filter in a
checkbox. let me explain:

on "$C$10:$C$1525" i want to have 5 diferents colorfilters ( yellow, blue,
red, green,orange and purple) and i want to, if the checkbox value is true
shoud filter by color. but, i need this: if select red( show only reds),
if i unselect red( show all), if i selected red , blue and yellow ( show the
three colors)... i think you understand. : pray2:
please help me,

thanks

Kenneth Hobs
08-23-2012, 05:46 AM
Welcome to the forum!

How will you select the color? I guess you mean by the Select event for those cells in that Range? What color property: interior cell, font, or conditional format? Not sure what you mean by unselect red to show all. To show all, simply uncheck the checkbox and the checkbox click event code can handle that.

HugoAvila
08-23-2012, 09:36 AM
there is my code

Private Sub CheckBox1_Click()
Dim Amarelo As Boolean, Azul As Boolean

If CheckBox1.Value = True Then
If CheckBox2.Value = True Then
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Amarelo" _
, Operator:=xlOr, Criteria2:="=Azul"
Else
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Amarelo"
Amarelo = True
End If
Else
If CheckBox2.Value = True Then
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Azul"
Azul = True
Else
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:=""
Amarelo = False
End If

End If
End Sub
Private Sub CheckBox2_Click()
Dim Azul As Boolean, Amarelo As Boolean

If CheckBox2.Value = True Then
If CheckBox1.Value = True Then
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Amarelo" _
, Operator:=xlOr, Criteria2:="=Azul"
Else
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Azul"
Azul = True
End If
Else
If CheckBox1.Value = True Then
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:="=Amarelo"
Amarelo = True
Else
ActiveSheet.Range("$C$7:$C$19").AutoFilter Field:=1, Criteria1:=""
Azul = False
End If
End If
End Sub

HugoAvila
08-23-2012, 09:38 AM
Welcome to the forum!

How will you select the color? I guess you mean by the Select event for those cells in that Range? What color property: interior cell, font, or conditional format? Not sure what you mean by unselect red to show all. To show all, simply uncheck the checkbox and the checkbox click event code can handle that.
i meant the color of the interior cell