Excel macro to highlight all cells that match value in current cell

前端 未结 2 1830
无人共我
无人共我 2021-01-07 11:19

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 c

2条回答
  •  太阳男子
    2021-01-07 11:33

    @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
    

提交回复
热议问题