简体   繁体   中英

Hightlight entire row if two columns match and are not blank

I looked and although there is likely something here, I'm too new to VBA to make it work.

I want to sort a range of data, and highlight a row if two particular columns match, as long as one column (K) is not blank.

More Details:
If column D = column K and column K is not blank, then highlight that row.
The amount of rows will change depending on the day.
The dataset starts at row 3.

I was thinking to use .end(xlup) to copy the formula.

This can be accomplished through conditional formatting, but I'm trying to build this in VBA so that it will be a one button solution.

Here is a version you can look at

Sub DoIt()

    Dim Rng As Range, C As Range

    Set Rng = Columns("K:K").SpecialCells(xlCellTypeConstants, 23)
    Columns("K:K").SpecialCells(xlCellTypeBlanks).EntireRow.Interior.Color = xlNone
    For Each C In Rng.Cells

        If C.Offset(, -7) = C Then

            Range(Cells(C.Row, "K"), Cells(C.Row, "D")).Interior.Color = vbYellow
        Else: Range(Cells(C.Row, "K"), Cells(C.Row, "D")).Interior.Color = xlNone

        End If

    Next C
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM