Excel宏以突出显示当前单元格中匹配值的所有单元格 [英] Excel macro to highlight all cells that match value in current cell

查看:222
本文介绍了Excel宏以突出显示当前单元格中匹配值的所有单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个宏,如果这些单元格的值与当前选定的单元格相同,它将自动突出显示当前工作表中的任何单元格。因此,如果当前选择了单元格B3,并且它包含值3,那么值将为3的所有其他单元格将被突出显示。

I'm looking for a macro that will automatically highlight any cells in the current worksheet if the value of those cells is the same as the currently-selected cell. So if cell B3 is currently selected, and it contains the value 3, then all other cells with a value of 3 will be highlighted.

任何想法?

推荐答案

@Reafidy提供了一个很好的宏,这样做将与条件格式化相同。

@Reafidy provided a good macro and this will do the same with conditional formatting

Sub HighLightCells()
ActiveSheet.UsedRange.Cells.FormatConditions.Delete
ActiveSheet.UsedRange.Cells.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
    Formula1:=ActiveCell
ActiveSheet.UsedRange.Cells.FormatConditions(1).Interior.ColorIndex = 4
End Sub

将其放在工作表选择更改事件

Put this in the sheet selection change event

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 call HighLightCells
End Sub

这篇关于Excel宏以突出显示当前单元格中匹配值的所有单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆