简体   繁体   中英

Highlight cell from another cells value (dyanmic range)

After digging through very similar posts I just can't find a solution to my unique request. I have been able to build a formula up to this point using those threads but I am just getting confused with having two IF statements.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If ActiveCell.Address = "$U$14" Then
    Dim rng As Range, cell As Range, LastRow As Long

    With Sheets("Sheet4")
        LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
    End With

    Set rng = Range("A2:A" & LastRow)

    'If O2:O200 is BLANK then highlight corresponding row (xlUp) in Column A yellow
    For Each cell In rng
        cell.Interior.ColorIndex = 27
    Next
Else
    cell.Interior.ColorIndex = 2
End If

End Sub

What I want to do is for every cell starting with O2 through O & LastRow IF it is blank then highlight corresponding row (xlUp) in column A.

(xlUp) - Because I want it to highlight the person's name and not just the row, meaning that person has not yet collected an Item.

Then when clicked off of cell U14 set it back to normal.

Sorry it is so sloppy, I tried to put as much in it as I could figure out on my own.

EXAMPLE: 例子

Thanks to Scott Craner for solving my highlighting issue using some clever conditional formatting, In order to solve the ability of toggling the conditional formatting via activating a cell I did the following in case anyone wants to know:

I set a conditional format ABOVE the feature that removed all formatting and checked "Stop If True". The formula used was:

    =NOT($U$12)
'U12 is the dedicated cell for displaying TRUE or FALSE, use any cell

I then utilized the following VBA to essentially toggle a cell to be true or false which then triggered the no format conditional to be true if a specific cell was selected and false when not:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If ActiveCell.Address = "$U$14" Or ActiveCell.Address = "$U$13" Then
    Range("$U$12").Value = True
Else
    Range("$U$12").Value = False
End If

End Sub

Now whenever I highlight the cells U13 or U14 all names within Column A that have not Collected will be highlighted.

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