跳至主要内容

如何在 Excel 中突出显示公式引用的所有单元格?

Author: Siluvia Last Modified: 2025-05-07

本文将介绍如何在 Excel 中突出显示公式引用的所有单元格。请按照以下两种方法操作完成。

使用快捷键突出显示公式引用的所有单元格
使用 VBA 代码突出显示公式引用的所有单元格


使用快捷键突出显示公式引用的所有单元格

您可以使用快捷键选择公式引用的所有单元格,然后手动为它们应用填充颜色。

1. 假设 E1 是一个公式单元格,您需要突出显示它引用的所有单元格。请选择公式单元格 E1,然后同时按下 Ctrl + [(左方括号)键。

A screenshot showing how to use Ctrl + [ to select cells referenced by a formula in Excel

2. 现在该公式引用的单元格已被选中,请指定一种填充颜色以突出显示它们。请参见截图:

A screenshot of selected referenced cells in Excel with fill color applied


使用 VBA 代码突出显示公式引用的所有单元格

您还可以运行 VBA 代码来突出显示 Excel 中公式引用的所有单元格。

1. 按下 Alt + F11 键打开 Microsoft Visual Basic for Applications 窗口。

2. 在 Microsoft Visual Basic for Applications 窗口中,请点击 插入 > 模块。然后复制并将以下 VBA 代码粘贴到模块窗口中。

VBA 代码:突出显示 Excel 中公式引用的所有单元格

Sub HighlightCellsReferenced()
    Dim rowCnt As Integer
    Dim i As Integer, j As Integer, strleng As Integer
    Dim strTxt As String, strFml As String
    Dim columnStr, cellsAddress As String
    Dim xRg As Range, yRg As Range
    On Error Resume Next
    Set xRg = Application.InputBox(Prompt:="Please select formula cell(s)...", _
    Title:="Kutools For Excel", Type:=8)
    
    strTxt = ""
    Application.ScreenUpdating = False
    For Each yRg In xRg
        If yRg.Value <> "" Then
            strFml = yRg.Formula + " "
            strFml = Replace(strFml, "(", " ")
            strFml = Replace(strFml, ")", " ")
            strFml = Replace(strFml, "-", " ")
            strFml = Replace(strFml, "+", " ")
            strFml = Replace(strFml, "*", " ")
            strFml = Replace(strFml, "/", " ")
            strFml = Replace(strFml, "=", " ")
            strFml = Replace(strFml, ",", " ")
            strFml = Replace(strFml, ":", " ")
              
            For j = 1 To Len(strFml)
                If Mid(strFml, j, 1) <> " " Then
                    cellsAddress = cellsAddress + Mid(strFml, j, 1)
                Else
                    On Error Resume Next
                    Range(cellsAddress).Interior.ColorIndex = 3
                    cellsAddress = ""
                End If
            Next
        End If
    Next yRg
    Application.ScreenUpdating = True
End Sub

3. 按下 F5 键运行代码。在弹出的 Kutools for Excel 对话框中,请选择一个或多个公式单元格,基于这些单元格您需要突出显示引用的单元格,然后点击 确定 按钮。请参见截图:

A screenshot of the Kutools for Excel dialog box to select formula cells for highlighting

现在,所有基于所选公式单元格引用的单元格都会立即以红色突出显示,如下图所示。

A screenshot showing all referenced cells highlighted in red after running the VBA code


相关文章

最佳办公效率工具

🤖 Kutools AI 助手:基于智能执行生成代码创建自定义公式分析数据并生成图表调用 Kutools 函数等功能,彻底改变数据分析方式…
热门功能查找、高亮或标记重复项 | 删除空行 | 合并不丢失数据的列或单元格 | 四舍五入 ...
高级 LOOKUP多条件 VLookup | 多值 VLookup | 多表查找 | 模糊查找 ....
高级下拉列表快速创建下拉列表 | 从属下拉列表 | 多选下拉列表 ....
列管理器添加指定数量的列 | 移动列 | 切换隐藏列的可见状态 | 比较区域和列 ...
精选功能网格聚焦 | 设计视图 | 增强编辑栏 | 工作簿与工作表管理器 | 资源库(自动文本) | 日期提取 | 合并数据 | 加密/解密单元格 | 按列表发送电子邮件 | 超级筛选 | 特殊筛选(筛选粗体/斜体/删除线...)...
排名前 15 的工具集12 种文本 工具添加文本删除特定字符等) | 50 多 种图表 类型甘特图等) | 40 多种实用 公式基于生日计算年龄等) | 19 种插入 工具插入二维码根据路径插入图片等) | 12 种转换 工具小写金额转大写汇率转换等) | 7 种合并与分割 工具高级合并行分割单元格等) | 还有更多...

使用 Kutools for Excel 提升您的 Excel 技能,体验前所未有的高效。 Kutools for Excel 提供超过 300 种高级功能来提高生产力并节省时间。 单击此处获取您最需要的功能...


Office Tab 将标签式界面引入 Office,让您的工作更加轻松

  • 在 Word、Excel、PowerPoint 中启用标签式编辑和阅读
  • 在同一窗口的新标签页中打开和创建多个文档,而不是在新窗口中进行操作。
  • 将您的生产力提升 50%,每天为您减少数百次鼠标点击!