简体   繁体   English

Excel宏突出显示与当前单元格中的值匹配的所有单元格

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

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. 因此,如果当前选择了单元格B3,并且该单元格包含值3,则所有其他值为3的单元格都将突出显示。

Any ideas? 有任何想法吗?

@Reafidy provided a good macro and this will do the same with conditional formatting @Reafidy提供了一个很好的宏,这将与条件格式相同

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

Use conditional formatting. 使用条件格式。

If you really need a macro then: 如果您确实需要宏,则:

Sub HighlightCells()
Dim rCell As Range

If ActiveCell.Value = vbNullString Then Exit Sub

Set rCell = ActiveCell

Do
    Set rCell = ActiveSheet.UsedRange.Cells.Find(ActiveCell.Value, rCell)

    If rCell.Address <> ActiveCell.Address Then
        rCell.Interior.Color = 65535
    Else
        Exit Do
    End If
Loop

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在excel中制作宏以突出显示比控制单元格大的单元格 - Making a macro in excel to highlight cells that are bigger than a control cell 突出显示另一个单元格中包含值的所有单元格 - Highlight all cells that contain a value in another cell Excel-匹配单元格并在右侧显示单元格的值 - Excel - Match Cells and Show Value of Cell to the Right Excel宏复制包含当前数组值的所有单元格并将其粘贴到新工作簿中 - Excel Macro to copy all cells containing current array value and paste them to a new workbook 当单元格的总和达到 Excel 中另一个单元格的值时突出显示单元格 - Highlight cells when its sum reached the value on another cell in Excel Excel-如何在突出显示具有相等值的单元格时自动突出显示单元格 - Excel - How to automatically highlight cells when a cell with equivalent value is highlighted Macro Excel可根据单元格匹配将范围单元格从一张纸复制到另一张纸,如果不匹配,则跳过单元格 - Macro Excel to copy range cells from one sheet to another based on cell match and skip cell if no match Excel宏-如果单元格具有特定值,则使接下来的2个单元格为空白 - Excel Macro - making next 2 cells blank if cell has a certain value Excel宏,根据另一个单元格值复制和粘贴多个单元格? - Excel macro, to copy and paste a multiple cells based on another cell value? Excel宏,用于更改单元格值以匹配工作表的名称 - Excel Macro for Changing cell value to match the name of the worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM