How To Delete module content using VBA in Microsoft Excel?
Tags: todeletemoduleconten, vbamacros
Published: 2021-10-11 04:14:36

---
title: How To Delete module content using VBA in Microsoft Excel?
published: true
date: 2021-10-08 12:04:10 UTC
tags: ToDeleteModuleConten,VBAMacros
canonical_url: https://geekexcel.com/how-to-delete-module-content-using-vba-in-microsoft-excel/
---

In this article, we will guide you on how to  **delete a module content using VBA ** in Microsoft Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub DeleteModuleContent(ByVal wb As Workbook, _
    ByVal DeleteModuleName As String)
' deletes the contents of DeleteModuleName in wb
' use this if you can't delete the module
    On Error Resume Next
    With wb.VBProject.VBComponents(DeleteModuleName).CodeModule
        .DeleteLines 1, .CountOfLines
    End With
    On Error GoTo 0
End Sub

```

- After that, you need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Save-the-Code-29.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Now, you need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Finally, after running the macro, you can **delete a module content** using VBA in Excel.

## Bottom-Line

We hope that this article gives you guidelines on how to  **delete a module content using VBA**  in Microsoft Excel. Please leave a comment in case of any  **queries,**  and don’t forget to mention your valuable  **suggestions**  as well. Thank you so much for Visiting Our Site!! Continue learning on **[Geek Excel](https://geekexcel.com/)!! **Read more on [**Excel Formulas**](https://geekexcel.com/excel-formula/) **!!**

**Keep Reading:**

- **[Excel Formulas to Highlight the Cells Between Two Dates!!](https://geekexcel.com/excel-formulas-to-highlight-the-cells-between-two-dates/)**
- **[How to Create User Defined Function through Excel VBA?](https://geekexcel.com/how-to-create-user-defined-function-through-excel-vba/)**
- **[Extract the Missing Values through Excel VBA](https://geekexcel.com/how-to-extract-the-missing-values-through-excel-vba/)**
- **[How to Copy a Formula in Excel Office 365 ~ Simple Guide!!](https://geekexcel.com/how-to-copy-a-formula-in-excel/)**
- **[How to Copy a Cell Formatting from One Cell to Other Cells in Excel 365?](https://geekexcel.com/how-to-copy-a-cell-formatting-from-one-cell-to-other-cells-in-excel-365/)**