OzGrid

Delete Excel Sheet Event Code Macro

< Back to Search results

 Category: [Excel]  Demo Available 

 

Delete Excel Sheet Event Code Macro

 

Delete Sheet Event Code Macro. Delete VBA Code With Code

 

Got any Excel/VBA Questions? Free Excel Help

Sheet Event Code

Excel is rich in event code for both the Workbook Object and the Sheet Object. For example, the worksheet change event is possibly the most popular of Sheet Events.

 

The macro below can be used to delete Sheet Code based on the sheet code names supplied to the select case statement within the Sheets Collection loop . It's ideal to use when you need to copy Sheets from a Workbook but do not want the code to copy with the Sheets.

You will have to go to Tools>Macro>Security - Trusted Publishers and check Trust access to Visual Basic Editor before running the code

Sub DeleteSheetEventCode()

''Needs Reference Set To _

    "Microsoft Visual Basic For Applications Extensibility"

'Tools>References.

Dim sSheet As Object, strName As String



        For Each sSheet In Sheets

        

            Select Case UCase(sSheet.Name)

                Case "SHEET1", "SHEET2", "SHEET3"

                    strName = sSheet.CodeName

                    

                    With ThisWorkbook.VBProject.VBComponents(strName).CodeModule

                            .DeleteLines 1, .CountOfLines

                    End With

                    

                Case Else

                   'Whatever

            End Select

            

        Next sSheet

End Sub

 

See also:

Delete Module After Running VBA Code
Deleting Excel Named Ranges
Delete Excel Workbook Event Code

 

Free Training Course: Lesson 1 - Excel Fundamentals

 

See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)