Delete VBA code

tlindeman

Active Member
Joined
Jun 29, 2005
Messages
313
Is it possible to create a macro to delete code from antoher macro on certain date, for example here is a samlple of my code:

Application.DisplayAlerts = False
Workbooks.Open Filename:="R:\ACCT\FINREPORTING\FS2011\Ratios\CAPX Ratios\Indebtedness.xlsx", UpdateLinks:=3
Windows("Enterprise KPI's.XLSM").Activate
Sheets("DEBT").Select
If Range("N16").Value = 1 Then
Range("N2").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$7"
Range("N3").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$8"
Range("N4").Formula = "=[Indebtedness.xlsx]Schedule_Jun'!$E$9"
Range("N8").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$13"
Range("N9").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$14"
Range("N10").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$15"
Range("N11").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$16"
Range("N12").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$17"
Else
Range("N2").Formula = "=L2"
Range("N3").Formula = "='Cash Flow Projection'!EG42/1000"
Range("N4").Formula = "=L4"
Range("N8").Formula = "=SUM('[2011 Balance Sheet by Month.xlsx]BS'!$BV$55+'[2011 Balance Sheet by Month.xlsx]BS'!$BV$61)"
Range("N9").Formula = "=L9"
Range("N10").Formula = "=L10"
Range("N11").Formula = "=L11"
Range("N12").Formula = "=L12"
End If
If Range("P16").Value = 1 Then
Range("P2").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$7"
Range("P3").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$8"
Range("P4").Formula = "=[Indebtedness.xlsx]Schedule_Jul'!$E$9"
Range("P8").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$13"
Range("P9").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$14"
Range("P10").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$15"
Range("P11").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$16"
Range("P12").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$17"
Else

After June, I would like to delete all the lines that refer to the ranges in N. After July I would like to delete all the lines that refer to range P. I know I can manually delete, however, I have extensive amount of code and would like to create the macro to run.

Thank You
Tony
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If it is easier I can seperate the data into multiple macros, so I just need a macro to delete a macro please, i would like to delete the macro June for example using VBA.

Thank You
Tony
 
Upvote 0
Hi,

Maybe this would help:

Code:
With Sheets("DEBT")
        If Date >= "01/06/2011" And Date <= "30/06/2011" Then
            If .Range("N16").Value = 1 Then
                .Range("N2").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$7"
                .Range("N3").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$8"
                .Range("N4").Formula = "=[Indebtedness.xlsx]Schedule_Jun'!$E$9"
                .Range("N8").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$13"
                .Range("N9").Formula = "=[Indebtedness.xlsx]Schedule_Jun!$E$14"
                .Range("N10").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$15"
                .Range("N11").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$16"
                .Range("N12").Formula = "[Indebtedness.xlsx]Schedule_Jun!$E$17"
            Else
                .Range("N2").Formula = "=L2"
                .Range("N3").Formula = "='Cash Flow Projection'!EG42/1000"
                .Range("N4").Formula = "=L4"
                .Range("N8").Formula = "=SUM('[2011 Balance Sheet by Month.xlsx]BS'!$BV$55+'[2011 Balance Sheet by Month.xlsx]BS'!$BV$61)"
                .Range("N9").Formula = "=L9"
                .Range("N10").Formula = "=L10"
                .Range("N11").Formula = "=L11"
                .Range("N12").Formula = "=L12"
            End If
        ElseIf Date >= "01/07/2011" And Date <= "31/07/2011" Then
            If .Range("P16").Value = 1 Then
                .Range("P2").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$7"
                .Range("P3").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$8"
                .Range("P4").Formula = "=[Indebtedness.xlsx]Schedule_Jul'!$E$9"
                .Range("P8").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$13"
                .Range("P9").Formula = "=[Indebtedness.xlsx]Schedule_Jul!$E$14"
                .Range("P10").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$15"
                .Range("P11").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$16"
                .Range("P12").Formula = "[Indebtedness.xlsx]Schedule_Jul!$E$17"
            End If
        End If
    End With
 
Upvote 0
sorry, I was wrong, I actually need it to delete the macro, including the else statement. I am running another macro on a certain date to copy paste special however, everytime I run this macro it will overwrite. So I need something like

Call Paste Special
Macro.June.Delete

I know that is not proper VBA, is it possible to do that?

Thank You
Tony
 
Upvote 0
Re: Delete VBA code (getting closer)

Ok,
The website gets me close, however, with the following code i get user value not defined. If you could help me with that error, I think I will have it. I am using office 2007

Sub DeleteProcedureFromModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
Dim ProcName As String

Set VBProj = ActiveWorkbook.VBPRoj
Set VBComp = VBProj.VBComponents("Module2")
Set CodeMod = VBComp.CodeModule

ProcName = "Indebtedness1"
With CodeMod
StartLine = .ProcStartLine(ProcName, vbext_pk_Proc)
NumLines = .ProcCountLines(ProcName, vbext_pk_Proc)
.DeleteLines StartLine:=StartLine, Count:=NumLines
End With
End Sub
 
Upvote 0
From the link

  • First, you need to set an reference to the VBA Extensibililty library. The library contains the definitions of the objects that make up the VBProject. In the VBA editor, go the the Tools menu and choose References. In that dialog, scroll down to and check the entry for Microsoft Visual Basic For Applications Extensibility 5.3. If you do not set this reference, you will receive a User-defined type not defined compiler error.
 
Upvote 0
That was already checked , any other ideas? Do I need to define the project as vbproject.enterprise KpI's ? enterprise Kpi's is my spreadsheet. However, VBA will recognise the ' in KPI's as a comment

Thank You for all your help
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top