I don't know if this is even possible

noexcelguru

New Member
Joined
Jan 18, 2011
Messages
40
I'm trying to get a CheckBox to find cells with certain values (variable1-4 in the code) and highlight the first cell of the row or the entire row ("A:Q") in orange (CI 45) and remove the color once unchecked.

Is it possible to range the entire column ("E:E"), and not just a specified number of rows down, like ("E7:E5000") in the code?

I've made this code, obviousley it doesn't work, but it might help you to get a clearer picture of what i would like the CheckBox to do


Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
    If ("E7:E5000") = "Variable1" Or "Variable2" Or "Variable3" Or "Variable4" Then
    firscellofrow = Cells.Interior.ColorIndex = xlNone
    End If
End If
If CheckBox1.Value = True Then
    If ("E7:E5000") = "Variable1" Or "Variable2" Or "Variable3" Or "Variable4" Then
    firscellsofrow = Cells.Interior.ColorIndex = 45
    End If
End If
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try:

Code:
Private Sub CheckBox1_Click()
    Dim r As Variant
    Dim Found As Boolean
    r = Application.Match("Variable1", Columns("E"), False)
    If Not IsError(r) Then
        Found = True
    Else
        r = Application.Match("Variable2", Columns("E"), False)
        If Not IsError(r) Then
            Found = True
        Else
            r = Application.Match("Variable3", Columns("E"), False)
            If Not IsError(r) Then
                Found = True
            Else
                r = Application.Match("Variable4", Columns("E"), False)
                If Not IsError(r) Then
                    Found = True
                End If
            End If
        End If
    End If
    If Found = True Then
        If CheckBox1.Value = False Then
            Rows(r).Interior.ColorIndex = xlNone
        Else
            Rows(r).Interior.ColorIndex = 45
        End If
    End If
End Sub
 
Upvote 0
Thanks for the reply, Andrew.

The code you provided me with works, however it only highlights one row and in "prioritized" order from top down. I guess its because of the Else-function?

Come to think of it, i might not have specified this in my post, but i would like all rows containing either text variable1, variable2, variable3 or variable4 in column E to be colored orange.
 
Upvote 0
Yes, that's probably the easisest solution. Do you know if i could turn on/ off conditional formating with the CheckBox, since the idea is to select wether or not you would like those rows highlighted?
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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