How To Delete a procedure from a module using VBA in Excel?
Tags: todeleteaprocedurefr, vbamacros
Published: 2021-10-12 01:52:06

---
title: How To Delete a procedure from a module using VBA in Excel?
published: true
date: 2021-10-11 06:09:46 UTC
tags: ToDeleteAProcedureFr,VBAMacros
canonical_url: https://geekexcel.com/how-to-delete-a-procedure-from-a-module-using-vba-in-excel/
---

In this blog post, we are going to see how to  **delete a procedure from a module using VBA**  in Microsoft Excel. Let’s get into this article!! 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, you need to  **create a macro to delete another macro from a module**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Sample-data-19.png)<figcaption>Sample data</figcaption>

- 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 need to  **copy and paste the code**  given below.

```
Option Explicit
Sub DeleteProcedureCode(ByVal DeleteFromModuleName As String, ByVal ProcedureName As String)
'Declaring variables
Dim VBCM As CodeModule, ProcStartLine As Long, ProcLineCount As Long
Dim WB As Workbook
On Error Resume Next
'Creating object of active workbook
Set WB = ActiveWorkbook
'Creating object of workbook module
Set VBCM = WB.VBProject.VBComponents(DeleteFromModuleName).CodeModule
'Checking whether the procedure exist in the codemodule
If Not VBCM Is Nothing Then
    
    ProcStartLine = 0
    
    'Function assigning the line no. of starting line for the procedure
    ProcStartLine = VBCM.ProcStartLine(ProcedureName, vbext_pk_Proc)
    
    If ProcStartLine > 0 Then
        
        'Function assign the no. of lines in the procedure
        ProcLineCount = VBCM.ProcCountLines(ProcedureName, vbext_pk_Proc)
        
        'Delete all the lines in the procedure
        VBCM.DeleteLines ProcStartLine, ProcLineCount
    
    End If
    Set VBCM = Nothing
End If
On Error GoTo 0
End Sub
Sub CallingProcedure()
'Declaring variables
Dim ModuleName, ProcedureName As String
'Getting value for module and procedure name from textboxes
ModuleName = Sheet1.TextBox1.Value
ProcedureName = Sheet1.TextBox2.Value
'Calling DeleteProcedureCode macro
DeleteProcedureCode ModuleName, ProcedureName
    
End Sub

```

- You have to  **save the code**  by selecting it and then  **close the window**.

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

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- Then, 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>

- Now, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

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

- Finally, after  **running the macro** , you have to **enter** the following **procedure** from a module to **delete**.

![](https://geekexcel.com/wp-content/uploads/2021/10/Output-18.png)<figcaption>Output</figcaption>

## Verdict

In the above post, you can learn the simple steps ** ** on how to  **delete a procedure from a module**  **using VBA**  in Microsoft Excel. Kindly, share your  **feedback**  in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!

**Read Ahead:**

- **[How To Import a module from a file using VBA in Microsoft Excel?](https://geekexcel.com/how-to-import-a-module-from-a-file-using-vba-in-microsoft-excel/)**
- **[How To Delete module content using VBA in Microsoft Excel?](https://geekexcel.com/how-to-delete-module-content-using-vba-in-microsoft-excel/)**
- **[Split Column through Excel office VBA – Easy tricks!!](https://geekexcel.com/how-to-split-column-through-excel-office-vba-easy-tricks/)**
- **[Excel Formulas to Find the First Row Number ~ Useful Tutorial!](https://geekexcel.com/excel-formulas-to-find-first-row-number/)**
- **[Find the Nth Largest Value in Excel Office 365 ~ Step-By-Step Procedure!!](https://geekexcel.com/find-the-nth-largest-value-in-excel/)**