[英]How to highlight multiple cells based on value on click in Excel
Context 语境
The Excel file is made up of 2 parts. Excel文件由两部分组成。
The Task 任务
I'd like to highlight the corresponding cells in the 2D-representations when I click on an ID in the data set . 当我单击数据集中的ID时,我想突出显示 2D表示形式中的相应单元格 。
This mockup-image shows the desired effect. 此模型图像显示了所需的效果。 As seen in the image, there are multiple cells with duplicate values in the 2D-represenatation that needs highlighting 如图所示,二维表示中有多个具有重复值的单元格需要突出显示
How would one go about doing something like this? 人们将如何做这样的事情?
You should use VBA as Jerry says. 您应该像Jerry所说的那样使用VBA。 I would look at the Worksheet_SelectionChange Event To trigger the highlighting and use a for-loop to go trough the columns to check if the corresponding cell needs to be highlighted. 我将查看Worksheet_SelectionChange事件以触发突出显示,并使用for循环遍历各列,以检查相应的单元格是否需要突出显示。
As Alex suggested, the Worksheet_SelectionChange Event was a the way to go. 正如Alex所建议的,Worksheet_SelectionChange事件是一种方法。 It is now working as intended. 现在它正在按预期工作。
Here's what I wrote. 这就是我写的
\\Constructor
\\ResetColors
\\MakeTrenchYellow subroutines here.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 1 And 3 - Selection.Cells.Count > 1 Then
Constructor
ResetColors
Dim SelectedRowTextjoin As String
SelectedRowTextjoin = Target.Offset(0, 6).Value
Dim CurrentResult As Variant
CurrentResult = Split(SelectedRowTextjoin, ", ")
Dim AmountOfElements As Integer
For Each Item In CurrentResult
AmountOfElements = AmountOfElements + 1
Next
For i = 1 To AmountOfElements
MakeTrenchYellow (CurrentResult(i - 1))
Next i
End If
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.