如果以下 VBA 代码适合您,请告诉我。
它将允许您突出显示任何工作表中的任何单元格(只要它在同一个工作簿中)。它可以帮助您进行加法、减法、乘法或除法 - 它甚至可以同时处理多个公式单元格。
Sub color_cells_in_formula()
Dim workrng As Range
Dim lcolor As Long
Set workrng = Application.Selection
Set workrng = Application.InputBox("Range", xTitleId, workrng.Address, Type:=8)
If Application.Dialogs(xlDialogEditColor).Show(10, 0, 125, 125) = True Then
lcolor = ActiveWorkbook.Colors(10)
Else
End If
For Each cell In workrng
If cell.Value <> "" Then
Dim result As String
result = cell.Formula
result = Replace(result, "(", " ")
result = Replace(result, ")", " ")
result = Replace(result, "-", " ")
result = Replace(result, "+", " ")
result = Replace(result, "*", " ")
result = Replace(result, "/", " ")
result = Replace(result, "=", " ")
result = Replace(result, ",", " ")
Dim cells() As String
cells = Split(Trim(result), " ")
For j = 0 To UBound(cells)
Range(cells(j)).Interior.Color = lcolor
Next j
End If
Next cell
End Sub