Skip to main content

在 Excel 中隱藏公式(完整指南)

Author: Kelly Last Modified: 2025-05-12

Excel 公式是進行計算和數據分析的強大工具。當公式位於 Excel 單元格中時,使用者可以通過兩種不同的方法來訪問它:雙擊單元格進入編輯模式,或者選擇單元格以在公式欄中顯示公式。

然而,如果您嘗試保護工作表,可能是出於保密、安全或其他考慮,您會發現您的公式仍然可以通過上述兩種方法被訪問。

如果您希望隱藏這些公式以防止用戶查看它們,本指南旨在幫助您。在這份全面的教程中,我們將引導您完成在 Excel 中隱藏公式的步驟,讓它們保持不可見,同時保留公式功能而不暴露它們。

A screenshot showing an Excel worksheet where the formula is hidden in the formula bar

視頻:在 Excel 中隱藏公式


輕鬆在 Excel 中隱藏公式

以下是防止用戶在選擇公式單元格時查看公式的步驟。需要注意的是,隱藏公式需要保護工作表,因此在工作表受保護後不允許進行任何更改。

步驟 1:選擇包含要隱藏公式的單元格

  • 要隱藏特定公式,請選擇包含這些公式的單元格。提示:如果公式位於非相鄰的單元格或區域中,按住「Ctrl」鍵並逐一選擇每個單元格。
  • 要隱藏當前工作表中的所有公式,請轉到「Home(主頁)」選項卡,在「Editing(編輯)」組中,點擊「Find & Select(查找與選擇)」>「Formulas(公式)」以選擇所有包含公式的單元格。
  • A screenshot showing how to click Find & Select > Formulas in Excel

步驟 2:啟用含公式單元格的隱藏屬性

  1. 右鍵單擊任意已選單元格,然後從上下文菜單中選擇「Format Cells(設置單元格格式)」以打開「Format Cells(設置單元格格式)」對話框。
    提示:或者,您可以使用快捷鍵「Ctrl」+「1」。
    A screenshot showing the Format Cells option in the context menu in Excel
  2. 在「Format Cells(設置單元格格式)」對話框中,切換到「Protection(保護)」選項卡,勾選「Hidden(隱藏)」選項,然後點擊「OK(確定)」。
    A screenshot of the Format Cells dialog in Excel, highlighting the Hidden option on the Protection tab
  3. 注意:正如對話框中的提示所示,隱藏公式在保護工作表之前不會生效。為了完成隱藏公式的過程,請務必按照下一步操作來保護工作表。

步驟 3:保護工作表

  1. 轉到「Review(審閱)」選項卡,然後選擇「Protect Sheet(保護工作表)」。
    A screenshot showing the Protect Sheet button on the Review tab in Excel
  2. 在「Protect Sheet(保護工作表)」對話框中,輸入密碼並點擊「OK(確定)」。
    A screenshot of the Protect Sheet dialog in Excel where you can set a password
    提示:在「Allow all users of this worksheet to:(允許此工作表的所有用戶進行以下操作:)」框中,您可以選擇允許或限制列出的操作,只需勾選或取消勾選每個操作旁邊的複選框即可。
  3. 隨後會出現「Confirm Password(確認密碼)」對話框,要求您重新輸入密碼。請再次輸入密碼並點擊「OK(確定)」。
  4. A screenshot of the Confirm Password dialog in Excel for protecting the worksheet

結果

現在,當您選擇包含公式的單元格時,您會注意到公式欄中不再顯示公式。

A screenshot showing an Excel worksheet where the formula is hidden in the formula bar

如果您嘗試雙擊該單元格,則會彈出一個對話框。

A screenshot of a pop-up dialog asking for a password when trying to edit a locked cell

(AD) 使用 Kutools for Excel 實現一體化 Excel 內容保護

難以找到啟用隱藏屬性或保護 Excel 工作表的位置嗎?讓「Kutools for Excel」讓您的生活更輕鬆!它將 Excel 的原生功能無縫整合到一個易於使用的功能區中,實現輕鬆的內容保護。無需再尋找選項,一切盡在純粹的簡潔之中!

Kutools for Excel - 超過 300 種必備工具,讓 Excel 功能更強大。永久免費享受 AI 功能!立即獲取


隱藏公式並保持特定單元格可編輯

您可能需要與他人共享工作簿,授予他們修改特定單元格的能力,同時保護您的公式不被查看或編輯。這是涉及數據輸入、統計分析及其他用途的工作表常見的需求。為實現這一目標,您可以選擇以下三種方法之一:


使用 Excel 的內建功能隱藏公式並保持特定單元格可編輯

在本節中,我將說明一種在工作表中隱藏公式的方法,同時保留特定單元格的編輯能力。這將通過配置單元格保護屬性和保護工作表來實現,具體步驟如下:

步驟 1:選擇包含要隱藏公式的單元格

  • 要隱藏特定公式,請選擇包含這些公式的單元格。提示:如果公式位於非相鄰的單元格或區域中,按住「Ctrl」鍵並逐一選擇每個單元格。
  • 要隱藏當前工作表中的所有公式,請轉到「Home(主頁)」選項卡,在「Editing(編輯)」組中,點擊「Find & Select(查找與選擇)」>「Formulas(公式)」以選擇所有包含公式的單元格。
  • A screenshot showing how to click Find & Select > Formulas in Excel

步驟 2:啟用含公式單元格的隱藏屬性

  1. 右鍵單擊任意已選單元格,然後從上下文菜單中選擇「Format Cells(設置單元格格式)」以打開「Format Cells(設置單元格格式)」對話框。
    提示:或者,您可以使用快捷鍵「Ctrl」+「1」。
    A screenshot showing the Format Cells option in the context menu in Excel
  2. 在「Format Cells(設置單元格格式)」對話框中,切換到「Protection(保護)」選項卡,勾選「Hidden(隱藏)」選項,然後點擊「OK(確定)」。
  3. A screenshot of the Format Cells dialog in Excel, highlighting the Hidden option on the Protection tab
  4. 注意:正如對話框中的提示所示,隱藏公式在保護工作表之前不會生效。為了完成隱藏公式的過程,請務必按照下一步操作來保護工作表。

步驟 3:禁用您希望保持可編輯單元格的鎖定屬性

  1. 選擇您希望保持可編輯的單元格。提示:您可以通過按住「Ctrl」鍵選擇非相鄰的單元格或區域。
  2. 按下「Ctrl」+「1」以打開「Format Cells(設置單元格格式)」對話框。
  3. 切換到「Protection(保護)」選項卡,取消勾選「Locked(鎖定)」選項,然後點擊「OK(確定)」。
  4. A screenshot of the Protection tab in the Format Cells dialog in Excel, with the Locked option unchecked

步驟 4:保護工作表

  1. 轉到「Review(審閱)」選項卡,然後選擇「Protect Sheet(保護工作表)」。
    A screenshot showing the Protect Sheet button on the Review tab in Excel
  2. 在「Protect Sheet(保護工作表)」對話框中,輸入密碼並點擊「OK(確定)」。
    A screenshot of the Protect Sheet dialog in Excel where you can set a password
    提示:在「Allow all users of this worksheet to:(允許此工作表的所有用戶進行以下操作:)」框中,您可以選擇允許或限制列出的操作,只需勾選或取消勾選每個操作旁邊的複選框即可。
  3. 隨後會出現「Confirm Password(確認密碼)」對話框,要求您重新輸入密碼。請再次輸入密碼並點擊「OK(確定)」。
  4. A screenshot of the Confirm Password dialog in Excel for protecting the worksheet

結果

在未鎖定的單元格中,您仍然可以輸入值,並且公式將繼續生成計算結果,同時保持不可見。

A GIF showing formulas hidden while specific cells are editable in Excel


使用 Kutools for Excel 隱藏公式並保持特定單元格可編輯

上述方法介紹了如何隱藏公式並保持特定單元格可編輯。但是,它要求您記住啟用隱藏屬性和禁用鎖定屬性的位置。此外,您還需要知道在哪裡保護工作表,這可能會很麻煩,特別是當您需要搜索這些選項時。

Kutools for Excel 的「Design(設計)」選項卡通過整合這些選項簡化了這些流程,使您更容易實現目標。下載並安裝 Kutools 後,請按照以下步驟操作:

Kutools for Excel 提供超過 300 種進階功能,簡化複雜任務,提升創造力與效率。 結合 AI 能力,Kutools 能夠精準自動化任務,讓數據管理變得輕而易舉。Kutools for Excel 的詳細資訊...免費試用...

步驟 1:選擇「Kutools Plus」>「Design View(設計檢視)」以顯示「KUTOOLS 設計」選項卡

A screenshot of the Design View button on the Kutools tab in Excel

步驟 2:選擇包含公式的單元格並點擊「Hide formulas(隱藏公式)」

  1. 選擇包含要隱藏公式的單元格。
    提示:
    • 要隱藏特定公式,請選擇包含這些公式的單元格。提示:如果公式位於非相鄰的單元格或區域中,按住「Ctrl」鍵並逐一選擇每個單元格。
    • 要隱藏當前工作表中的所有公式,請轉到「Home(主頁)」選項卡,在「Editing(編輯)」組中,點擊「Find & Select(查找與選擇)」>「Formulas(公式)」以選擇所有包含公式的單元格。
      A screenshot showing how to click Find & Select > Formulas in Excel
  2. 在「KUTOOLS 設計」選項卡上選擇「Hide formulas(隱藏公式)」。
  3. A screenshot of the Hide formulas button on the Kutools Design tab
  4. 提示:將出現一個對話框,告知您所選單元格中的公式在工作表受保護後將被隱藏。點擊「OK(確定)」。
    A screenshot of the Kutools dialog box notifying that formulas will be hidden after protecting the worksheet

步驟 3:選擇您希望保持可編輯的單元格並選擇「Unlock Cells(解鎖單元格)」

提示:要保持多個非相鄰單元格或區域可編輯,請按住「Ctrl」鍵並逐一選擇每個單元格,然後選擇「Unlock Cells(解鎖單元格)」。

A screenshot of the Unlock Cells button on the Kutools Design tab in Excel

步驟 4:保護工作表

  1. 在「KUTOOLS 設計」選項卡上,選擇「Protect Sheet(保護工作表)」以打開「Protect Sheet(保護工作表)」對話框。然後輸入密碼並點擊「OK(確定)」。
    A screenshot showing the Protect Sheet dialog in the Kutools Design tab with a password being set
    提示:在「Allow all users of this worksheet to:(允許此工作表的所有用戶進行以下操作:)」框中,您可以選擇允許或限制列出的操作,只需勾選或取消勾選每個操作旁邊的複選框即可。
  2. 隨後會出現「Confirm Password(確認密碼)」對話框,要求您重新輸入密碼。請再次輸入密碼並點擊「OK(確定)」。
  3. A screenshot of the Confirm Password dialog in Excel for protecting the worksheet

結果

通過這些步驟,您可以有效地在 Excel 中隱藏公式,同時允許特定單元格保持可編輯。

A GIF showing formulas hidden while specific cells are editable in Excel

Kutools for Excel - 超過 300 種必備工具,讓 Excel 功能更強大。永久免費享受 AI 功能!立即獲取


使用 VBA 隱藏公式並保持特定單元格可編輯

在本節中,我將演示如何使用 VBA 宏高效地從公式欄中隱藏公式,並同時保持特定單元格的編輯能力。

步驟 1:創建新模塊

  1. 按下「Alt」+「F11」以打開「Visual Basic for Applications (VBA)」編輯器。
  2. 點擊「Insert(插入)」>「Module(模塊)」以創建新模塊。
  3. A screenshot of the VBA editor showing Insert > Module option to add a new module

步驟 2:將 VBA 程式碼複製到模塊窗口

複製以下 VBA 程式碼並將其粘貼到打開的「Module(模塊)」窗口中。

Sub HideFormulasAndProtectWithEditableCells()
'Update by ExtendOffice
    Dim xWs As Worksheet
    Dim xWb As Workbook
    Dim xPassword As String
    xPassword = "123456" ' Replace "123456" with the actual password for protecting the sheet
    Set xWb = Application.ActiveWorkbook
    
    Set xWs = xWb.Sheets("Sheet1") ' Replace "Sheet1" with your sheet's name
    xWs.Unprotect Password:=xPassword
    For Each cell In xWs.UsedRange
        If cell.HasFormula Then
            cell.FormulaHidden = True
        End If
        cell.Locked = True
    Next cell
    
    On Error Resume Next
    Set xEditableRange = Application.InputBox("Select the range to keep editable", "Kutools for Excel", Type:=8)

    If Not xEditableRange Is Nothing Then
        xEditableRange.Locked = False
    End If
    xWs.Protect Password:=xPassword, UserInterfaceOnly:=True
End Sub

注意:

  • 您應該將第 6 行的「123456」替換為實際用於保護工作表的密碼。
  • 您應該將第 9 行的「Sheet1」替換為您要保護的工作表的實際名稱。

步驟 3:運行 VBA 程式碼

  1. 在「Module(模塊)」窗口中,按下「F5」或點擊 Run button 按鈕以執行粘貼的程式碼。
  2. 在出現的「Select the range to keep editable(選擇要保持可編輯的範圍)」對話框中,選擇您希望保持可編輯的單元格,然後點擊「OK(確定)」。
  3. A screenshot of the Select the range to keep editable dialog box in Excel

結果

現在,使用您提供給 VBA 的密碼,工作表已被保護。此工作表中的所有公式都被隱藏,並且所選單元格是可編輯的。

A GIF showing formulas hidden while specific cells remain editable in Excel


如果想要取消隱藏公式該怎麼辦?

要取消隱藏公式,只需取消保護您的工作表:轉到「Review(審閱)」選項卡,選擇「Unprotect Sheet(取消保護工作表)」,輸入密碼,然後點擊「OK(確定)」。

The Unprotect Sheet button on the ribbon in Excel

注意:

  • 如果您計劃在未來保護工作表,同時允許用戶查看公式,請選擇這些公式單元格並按下「Ctrl」+「1」以打開「Format Cells(設置單元格格式)」對話框。然後轉到「Protection(保護)」選項卡並取消勾選「Hidden(隱藏)」框。
  • 如果您取消勾選「Locked(鎖定)」框以在保護工作表後使單元格可編輯,但後來希望再次保護工作表且不允許用戶編輯這些單元格,請選擇這些單元格,按下「Ctrl」+「1」以打開「Format Cells(設置單元格格式)」對話框,轉到「Protection(保護)」選項卡,並勾選「Locked(鎖定)」選項旁的框。
  • 提示:如需協助識別未鎖定或隱藏的單元格,請參閱下一節
  • A screenshot of the Protection tab in the Format Cells dialog in Excel

如何識別公式隱藏單元格和未鎖定單元格

當您調整了某些單元格的隱藏或鎖定屬性後,找出哪些單元格已被修改可能是一項繁瑣的任務。通常需要使用 Excel 的「Format Cell(設置單元格格式)」對話框逐一檢查每個單元格的格式。

然而,使用「Kutools for Excel」,您可以通過單擊一次簡化此過程。它快速突出顯示那些屬性已被更改的單元格,使識別公式隱藏單元格和未鎖定單元格變得輕鬆且省時。

Kutools for Excel 提供超過 300 種進階功能,簡化複雜任務,提升創造力與效率。 結合 AI 能力,Kutools 能夠精準自動化任務,讓數據管理變得輕而易舉。Kutools for Excel 的詳細資訊...免費試用...

安裝 Kutools for Excel 後,導航至「Kutools Plus」>「Design View(設計檢視)」以訪問「KUTOOLS 設計」選項卡。從那裡,點擊「Highlight Unlocked(高亮未鎖定區域)」以標記所有未鎖定的單元格(移除鎖定屬性的單元格),或者點擊「Highlight Hidden(高亮隱藏公式區域)」以識別所有公式隱藏單元格(添加隱藏屬性的單元格)。

A GIF showing the Highlight Unlocked and Highlight Hidden options in Kutools for Excel

Kutools for Excel - 超過 300 種必備工具,讓 Excel 功能更強大。永久免費享受 AI 功能!立即獲取

以上是與在 Excel 中隱藏公式相關的所有內容。我希望您覺得本教程有幫助。如果您想探索更多 Excel 技巧,請點擊這裡以訪問我們超過數千篇教程的廣泛收藏。