ActiveX Checkbox - Hide rows based on color

LSDSCS

New Member
Joined
Jan 18, 2019
Messages
1
[FONT=&quot]Is there VBA code to hide all rows that are a certain color if a checkbox is checked?

Here is a screengrab of what I am working with - [/FONT]
https://ibb.co/8Kqgpxw

[FONT=&quot]I want to be able to uncheck the checkbox next to "A" in B1 and have all of the yellow rows get hidden.

I used a simple code to get the concept to work, I just need to add the color aspect to it
[/FONT]
Private Sub CheckBox2_Click()
[7:9].EntireRow.Hidden = Not CheckBox2
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Change B1:E1 by the range of cells where the checkbox are, change 4 to 15 for the rows you want to review.


Code:
Sub Hide_Rows(wcheck)
    Application.ScreenUpdating = False
    Set rango = Range("B1:E1")  'range of checkbox
    For Each celda In rango
        If Not Intersect(wcheck.TopLeftCell, celda) Is Nothing And _
           Not Intersect(wcheck.BottomRightCell, celda) Is Nothing Then
            wcolor = celda.Interior.Color
            For i = 4 To 15   'initial and final row
                If Range("A" & i).Interior.Color = wcolor Then
                    Rows(i).EntireRow.Hidden = Not wcheck
                End If
            Next
        End If
    Next
End Sub
'
Private Sub CheckBox1_Click()
    Call Hide_Rows(CheckBox1)
End Sub
Private Sub CheckBox2_Click()
    Call Hide_Rows(CheckBox2)
End Sub
Private Sub CheckBox3_Click()
    Call Hide_Rows(CheckBox3)
End Sub
Private Sub CheckBox4_Click()
    Call Hide_Rows(CheckBox4)
End Sub
 
Last edited:
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...ctivex-checkbox-hide-rows-based-on-color.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,027
Members
448,543
Latest member
MartinLarkin

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