Hide Excel Formulas (with Protecting Sheet & Without It)

This article covers the application of Format Cells dialog box and Review tab to hide Excel formulas. Also, we show the use of VBA code to do the same thing. But these two methods require protecting sheet. For your convenience, we have demonstrated hiding Excel formulas without protecting sheet.

Hiding Excel formulas is a useful technique employed to safeguard sensitive information and maintain the integrity of spreadsheet data. While Excel formulas are powerful tools for performing calculations and automating tasks, there are situations where it becomes necessary to conceal them from view. Whether you are protecting proprietary formulas or preserving confidentiality, this guide delves into different strategies and techniques to effectively hide Excel formulas, ensuring that your data remains secure while maintaining the desired level of transparency.

Over view of hide formula


Download Practice Workbook


Hide Excel Formulas: 3 Suitable Ways


1. Hide Excel Formula Using Format Cells Option with Protecting Sheet

1.1 Hide Manually Selected Cells Containing Excel Formulas

  • First, we need to select the column where we want to hide the formula.
  • Then, right-click on selected cells and select Format Cells….

Selecting Format cells

  • Next, go to the Protection tab and check the box before the Hidden After that, press OK.

Check protection and hidden

  • Now, select Review >> Protect Sheet.

Protect worksheet

  • Following that, choose your password as you wish and press OK. You can protect anything you want in the Protect Sheet.

Protect sheet window

  • Now, you will see that the Excel formulas are hidden.

Over view of hide formula


1.2 Hide Automatically Selected Cells Containing Excel Formulas

  • First, select the whole sheet.

Select all cells

  • Now, we have to search for cells with formulas.
  • So, select Home >> Editing >> Find & Select.

Searching formula based cells

  • Then select Go To Special….

Selecting Go To Special

  • Next, check the circle before the Formulas option and (also keep the boxes of the Numbers, Text, Logicals, Errors options selected).
  • Finally, press OK.

Selecting formulas

  • Now, you will see that the cells having formula are selected.

Cells with formula selected

  • Now press Ctrl + 1 to get Format Cells window, and check Hidden and Locked
  • Then press OK.

Format cell window

  • Select Protect Sheet from the Review tab.

Protect worksheet

  • Then press OK in the Protect Sheet.

Selecting formulas

  • Now, you can see that formula is hidden.

Over view of hide formula


2. Hide Excel Formulas Using VBA with Protecting Sheet

  • At first, you need to Select ‘Alt+F11’ in order to run the VBA editor. If there is no Developer tab, you can adjust it by customizing the ribbon.
  • After opening the VBA editor, click on ‘Insert’.

  • From the ‘Insert’ tab, select ‘Module’.

  • In the opened Module window, type the following VBA code:
Sub LockAndHideAllCellsWithFormulas()

With ActiveSheet
.Unprotect
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Cells.SpecialCells(xlCellTypeFormulas).FormulaHidden = True
.Protect AllowDeletingRows:=True
End With

End Sub

Hide Formula in Excel with VBA Codes

  • Minimize the Module window and editor.
  • Then click on the ‘View’ tab and go to the ‘Macros’

  • Select the given ‘Macro Name’ and click ‘Run’.

Conceal Formula in Excel with VBA Codes

  • After using VBA codes, you can protect your worksheet with the cell formula hidden.

Over view of hide formula

Read More: How to Hide Formula in Excel Using VBA


3. Hide Excel Formulas Without Protecting Sheet

  • First, we have to right-click on the worksheet and select View Code to add code for that worksheet.

Right click on worksheet

  • Then, you have to write the code for hiding the formulas.

VBA code for hiding formula

  • You can copy the code from here.
Dim iDictionary As New Dictionary
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iCell As Range
Dim iRange As Range
Set iRange = Range("B5:G11")
If iDictionary.Count <> iRange.Count Then
    For Each iCell In iRange
        iDictionary.Add iCell.Address, iCell.FormulaR1C1
    Next
End If
If (Target.Count = 1) And (Not Application.Intersect(iRange, Target) Is Nothing) And (Target.HasFormula) Then
    With Target
        .Value = .Value
    End With
Else
    For Each iCell In iRange
        iCell.Formula = iDictionary.Item(iCell.Address)
    Next
End If
End Sub
Code Breakdown

Dim iDictionary As New Dictionary

This line declares a new dictionary object called iDictionary. The Dictionary class allows you to store key-value pairs.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

This line defines a private subroutine called Worksheet_SelectionChange, which is an event handler that gets triggered whenever a different cell or range is selected on the worksheet. The Target parameter represents the selected range.

Dim iCell As Range

Dim iRange As Range

Set iRange = Range(“B5:G11”)

These lines declare two range variables: iCell and iRange. iRange is set to the range “B5:G11”.

If iDictionary.Count <> iRange.Count Then

    For Each iCell In iRange

        iDictionary.Add iCell.Address, iCell.FormulaR1C1

    Next

End If

This conditional statement checks if the count of items in the dictionary (iDictionary.Count) is not equal to the count of cells in iRange. If the counts are different, it means the dictionary is empty or has different contents than the range. In that case, the code enters a loop and iterates over each cell iCell within iRange. It adds an entry to the dictionary using the cell’s address as the key and the cell’s formula in R1C1 notation as the value. This populates the dictionary with the initial formulas of the cells in iRange.

If (Target.Count = 1) And (Not Application.Intersect(iRange, Target) Is Nothing) And (Target.HasFormula) Then

    With Target

        .Value = .Value

    End With

This piece of code is to check whether the range holds the formula or not. If the intersection of the range doesn’t fulfil the above condition, then it replaces the value in the cell with the value that it has..

Else

    For Each iCell In iRange

        iCell.Formula = iDictionary.Item(iCell.Address)

    Next

End If

End Sub

Otherwise, pass the cell address as the argument of each item.

  • Now, we will select Tools and select References….

Add reference

  • Then, we have to check Microsoft Scripting Runtime from References-VBAProject

Check Microsoft Scripting Runtime

  • Now, when we select any cells with formulas, it will hide the formula.

Formula is hidden

Read More: How to Hide Formula in Excel without Protecting Sheet


How to Unhide Formulas in Excel

  • To unprotect your sheet, go to Review >> Protect >> Unprotect Sheet.

Unprotect shit

  • Then you can see the formulas again.

Showing Formula


How to Show Formulas in Excel

  • Right-click on cells, and you will see the formula.

Showing Formula


Things to Remember

  • Do not forget to select Protect >> Protect Sheet from Review Otherwise, it will not hide the formulas.
  • Always review and recheck your formula. Otherwise, it can cause errors in your whole worksheet. Because suppose you protected the worksheet with the wrong formula and the formula is hidden. Nobody will understand and find out what is wrong. So in those cases, worksheet will be discarded. So, recheck the formula.

Conclusion

To summarize, hiding Excel formulas helps protect sensitive information and improve the appearance of your spreadsheet. You can hide formulas by changing cell formatting, using conditional formatting, or applying for worksheet or workbook protection. Remember to test and verify the accuracy of hidden formulas and consider potential risks, such as accidental changes or unauthorized access. By understanding these methods, you can ensure data security while maintaining transparency in your Excel spreadsheets.


Frequently Asked Questions

1. Can I still use hidden formulas in my spreadsheet?

Yes, hiding formulas does not disable their functionality. Even though the formulas are hidden from view, they continue to calculate and update the results in your spreadsheet.

2. Can hidden formulas be seen or modified by others with advanced Excel knowledge?

While casual users may not easily see or modify hidden formulas, those with advanced Excel knowledge and experience may have techniques to uncover or modify hidden formulas. It’s important to be cautious and use additional security measures, such as password protection or restricted user permissions, to further safeguard your hidden formulas.

3. Will hiding Excel formulas affect the performance of my spreadsheet?

Hiding formulas themselves does not significantly impact the performance of your spreadsheet. However, if your spreadsheet contains complex calculations or a large number of hidden formulas, it may still have an impact on overall spreadsheet performance. It’s always a good practice to optimize your formulas and keep the spreadsheet size manageable for optimal performance.


Hide Excel Formulas: Knowledge Hub


<< Go Back to Excel Formulas | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Joyanta Mitra
Joyanta Mitra

Joyanta Mitra, a BSc graduate in Electrical and Electronic Engineering from Bangladesh University of Engineering and Technology, has dedicated over a year to the ExcelDemy project. Specializing in programming, he has authored and modified 60 articles, predominantly focusing on Power Query and VBA (Visual Basic for Applications). His expertise in VBA programming is evident through the substantial body of work he has contributed, showcasing a deep understanding of Excel automation, and enhancing the ExcelDemy project's resources with valuable... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo