[英]Making a macro in excel to highlight cells that are bigger than a control cell
[英]Excel macro to highlight all cells that match value in current cell
我正在尋找一個宏,該宏將自動突出顯示當前工作表中的任何單元格(如果這些單元格的值與當前選定的單元格相同)。 因此,如果當前選擇了單元格B3,並且該單元格包含值3,則所有其他值為3的單元格都將突出顯示。
有任何想法嗎?
@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
將此放入工作表選擇更改事件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
call HighLightCells
End Sub
使用條件格式。
如果您確實需要宏,則:
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.