How to Protect All Cells with Formulas using Macros in Excel 365?
Tags: protectallcellswithf, vbamacros
Published: 2021-02-13 08:52:39

---
title: How to Protect All Cells with Formulas using Macros in Excel 365?
published: true
date: 2021-02-12 09:16:10 UTC
tags: Protectallcellswithf,VBAMacros
canonical_url: https://geekexcel.com/how-to-protect-all-cells-with-formulas-using-macros-in-excel-365/
---

In this article, we will see how to protect formula cells in Excel Office 365 with the help of Macros. [VBA](https://geekexcel.com/excel-office-365-vba-overview-definition-and-examples/) & Macros will make your work simple and easy, you can do anything with a few clicks. If you want to know, how to **[protect all cells](https://geekexcel.com/how-to-protect-the-cell-in-microsoft-excel-365/) with formulas using Macros**, then we will walk you through the steps needed to do this task. Try the below steps.

## Steps to Protect Formula Cells using Macros:

You need to follow the below steps to protect formula cells using Macros.

- The following screenshot has shown the **example formula cells** in the Excel worksheet. We are going to protect those cells with Macros.

![Example](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_7V4QwikP3N.png)<figcaption id="caption-attachment-21807">Example</figcaption>

- On the **Developer Tab, select** the **Visual Basic** option under the **Code** section.

![Select Visual Basic option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Select-Visual-Basic-option-4.png)<figcaption id="caption-attachment-14755">Select the Visual Basic option</figcaption>

- Then you need to copy and paste the code given below.

VBA code to protect formula cells using Macros

Sub ProtectAllCellsWithFormula()

With ActiveSheet

.Unprotect

.Cells.Locked = False

.Cells.SpecialCells(xlCellTypeFormulas).Locked = True

.Protect AllowDeletingRows:=True

End With

End Sub

- You need to **save the code** by selecting it. Then **close** the **window.**

![Enter the code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_PUuSiTWP0H.png)<figcaption id="caption-attachment-21808">Enter the code</figcaption>

- You have to open the sheet containing the data. On the **Developer Tab, choose** the **Macros option** in the **Code** section.

![Choose the Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/09/Choose-the-Macros-option-2.png)<figcaption id="caption-attachment-14747">Choose the Macros option</figcaption>

- You need to make sure that your macro is selected and **click** the **Run** button.

![Click Run button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_Iuhg6jRSCE.png)<figcaption id="caption-attachment-21809">Click Run button</figcaption>

- Now, you can see that all the formula cells are protected. If you try to edit the protected cells, it will display the warning message as shown in the below image.

![Output](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2021/02/EXCEL_8gf2m682aC.png)<figcaption id="caption-attachment-21810">Output</figcaption>

## Summary:

In the above article, you can easily learn the steps to **protect all cells with formulas using Macros** in Excel Office 365. Leave your **queries/feedback** in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

#### Keep Reading:

- [Remove Extra Spaces from Selection Using Macros (VBA) in Excel!!](https://geekexcel.com/remove-extra-spaces-from-selection-using-macros-vba-in-excel/)
- [Add a Degree Symbol to Selection Range using Macros (VBA) in Excel!](https://geekexcel.com/add-a-degree-symbol-to-selection-range-using-macros-vba-in-excel/)
- [Remove Characters at the Start using Macros (VBA) in Excel 365!!](https://geekexcel.com/remove-characters-at-the-start-using-macros-vba-in-excel-365/)