Skip to main content

如何在 Excel 中過濾列時突出顯示該列或列標題?

Author: Siluvia Last Modified: 2025-05-12

對於具有多列的表格,由於過濾列沒有明顯的符號(除了 filter icon 標記外),很難一眼看出哪一列被過濾。如果你想讓過濾列在表格中顯得突出,本文中的方法可以幫助你。

如果使用 VBA 程式碼過濾,則突出顯示列標題或整列


如果使用 VBA 程式碼過濾,則突出顯示列標題或整列

如下方截圖所示,如果某列在表格範圍內被過濾,你需要突出顯示整列或僅突出顯示列標題,請應用以下 VBA 程式碼。

sample data

1. 按下 Alt + F11 鍵以打開 Microsoft Visual Basic for Applications 視窗。

2. 在 Microsoft Visual Basic for Applications 視窗中,請點擊 插入 > 模組。然後將以下 VBA 程式碼複製到模組視窗中。

VBA 程式碼:如果列被過濾,則突出顯示列標題

Sub HighLightTitle()
'Updated by Extendoffice 2017/9/12
    Dim xRg As Range
    Dim I As Integer
    Dim xCount As Long
    Dim xRgCol As Long
    Dim xAddress As String
    Dim xFilterCount As Long
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the first cell of the table range:", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xRg.Select
    With xRg(1).Parent.AutoFilter
        xFilterCount = .Range.Columns.Count
        xRgCol = xRg.Offset(1).Column - .Range.Column + 1
        For I = xRgCol To xFilterCount
            xCount = xRg.Offset(, I - xRgCol).Column - .Range.Column + 1
            With .Filters(xCount)
                If .On Then
                    xRg.Offset(, I - xRgCol).Interior.Color = 16736553
                End If
            End With
        Next
    End With
End Sub

要突出顯示整列(如果它在表格中被過濾),請將以下 VBA 程式碼複製並貼到模組視窗中。

VBA 程式碼:如果列被過濾,則突出顯示整列

Sub HighLightCols()
'Updated by Extendoffice 2017/9/12
    Dim xRg As Range
    Dim xCount As Long
    Dim xRgCol As Long
    Dim xAddress As String
    Dim xRgFilter As Range
    Dim xFilterCount As Long
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the first cell of the table range:", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    xRg.Select
    With xRg(1).Parent.AutoFilter
        xFilterCount = .Range.Columns.Count
        xRgCol = xRg(1).Column - .Range.Column + 1
        For I = xRgCol To xFilterCount
            xCount = xRg.Offset(, I - xRgCol).Column - .Range.Column + 1
            With .Filters(xCount)
                Set xRgFilter = xRg.Offset(, I - xRgCol).Parent.AutoFilter.Range.Columns(xCount)
                If .On Then
                    xRgFilter.Interior.Color = 16736553
                End If
            End With
        Next
    End With
End Sub

3. 按下 F5 鍵來執行程式碼。在彈出的 Kutools for Excel 對話框中,請選擇需要突出顯示過濾列標題或整列的表格的第一個單元格,然後點擊 確定 按鈕。

 select the first cell of the table to highlight the filtered column header or entire filtered column

然後,如果該列在特定表格中被過濾,列標題或整列將立即被突出顯示。請參閱截圖:

如果列在表格中被過濾,則突出顯示列標題:

Highlight column header if the column is filtered in the table

如果列在表格中被過濾,則突出顯示整列:

Highlight entire column if it is filtered in the table

a screenshot of kutools for excel ai

使用 Kutools AI 解鎖 Excel 的魔法

  • 智能執行:執行單元格操作、分析數據並創建圖表——所有這些都由簡單的指令驅動。
  • 自訂公式:生成量身定制的公式,簡化您的工作流程。
  • VBA 編碼:輕鬆編寫和實現 VBA 代碼。
  • 公式解釋:輕鬆理解複雜的公式。
  • 文本翻譯:打破電子表格中的語言障礙。
通過人工智能工具增強您的 Excel 能力。立即下載,體驗前所未有的效率!

最佳辦公效率工具

🤖 Kutools AI 助手:基於智能執行方式革新數據分析:智能執行   |  生成代碼  |  創建自訂公式  |  分析數據並生成圖表  |  調用 Kutools 函數
熱門功能查找、標記重複值或識別重複項   |  刪除空行   |  合併列或單元格而不丟失數據   |   四捨五入無需公式 ...
高級 LOOKUP多條件 VLookup    多值 VLookup  |   多表查找   |   模糊查找 ....
高級下拉列表快速創建下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
列管理器添加特定數量的列  |  移動列  |  切換隱藏列的可見狀態  |  比較區域和列 ...
特色功能網格聚焦   |  設計檢視   |   增強編輯欄    工作簿與工作表管理器   |  資源庫(自動文本)   |  日期提取器   |  合併資料   |  加密/解密儲存格    按列表發送電子郵件   |  超級篩選   |   特殊篩選(篩選粗體/斜體/刪除線...) ...
頂級 15 種工具集12 個文本工具添加文本刪除特定字符、...)   |   50+ 圖表 類型甘特圖、...)   |   40+ 實用 公式基於生日計算年齡、...)   |   19 個插入工具插入QR碼根據路徑插入圖片、...)   |   12 個轉換工具金額轉大寫匯率轉換、...)   |   7 個合併與分割工具高級合併行分割儲存格、...)   |   ... 還有更多

使用 Kutools for Excel 提升您的 Excel 技巧,體驗前所未有的高效。 Kutools for Excel 提供超過 300 種高級功能來提高生產力並節省時間。  點擊這裡獲取您最需要的功能...


Office Tab 將標籤式界面帶到 Office,讓您的工作更加輕鬆

  • 在 Word、Excel、PowerPoint、Publisher、Access、Visio 和 Project 中啟用標籤式編輯和閱讀。
  • 在同一窗口的新標籤中打開和創建多個文檔,而不是在新窗口中。
  • 將您的生產力提高 50%,每天為您減少數百次鼠標點擊!