[英]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.
到目前为止,我已经能够使用这些线程构建一个公式,但我只是对有两个 IF 语句感到困惑。
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.我想要做的是对于从 O2 到 O & LastRow 的每个单元格,如果它是空白的,然后突出显示 A 列中的相应行(xlUp) 。
(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. (xlUp) - 因为我希望它突出显示这个人的名字,而不仅仅是行,这意味着那个人还没有收集到一个项目。
Then when clicked off of cell U14 set it back to normal.然后当点击单元格 U14 时将其设置回正常。
Sorry it is so sloppy, I tried to put as much in it as I could figure out on my own.对不起,它太草率了,我试着把我自己能想到的尽可能多的放进去。
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:感谢 Scott Craner 使用一些巧妙的条件格式解决了我的突出显示问题,为了解决通过激活单元格来切换条件格式的能力,我做了以下事情以防万一有人想知道:
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:然后,我使用以下 VBA 基本上将单元格切换为真或假,然后触发无格式条件为真,如果选择特定单元格,则为假:
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.现在,每当我突出显示单元格 U13 或 U14 时,A 列中尚未收集的所有名称都将突出显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.