Hello everybody,
who can tell me what is wrong with my code ? (how do I attach a file ?)
From a sub() I want to delete some rows in another Sub()
In this case from row 3 to the next to last row.
As the length of my Sub() is never the same, I HAVE to put the number of rows in a variable.
But it aborts when instruction deletelines is used !
What should I do ?
In advance, thank you for your help
who can tell me what is wrong with my code ? (how do I attach a file ?)
From a sub() I want to delete some rows in another Sub()
In this case from row 3 to the next to last row.
As the length of my Sub() is never the same, I HAVE to put the number of rows in a variable.
But it aborts when instruction deletelines is used !
What should I do ?
In advance, thank you for your help
Code:
Sub Squeeze()
Dim Start As Integer, TheEnd As Integer, TargettedFirstRow As Integer, TargettedLastRow As Integer
With ThisWorkbook.VBProject.VBComponents("Module2").CodeModule
Start = .ProcStartLine("Program", 0)
' gives position of the first row in Sub Program()
TheEnd = .ProcCountLines("Program", 0)
' gives position of the last row in Sub Program()
TargettedFirstRow = Start + 2
' because I want to keep at least one row between Sub() et End Sub()
TargettedLastRow = TheEnd - 1
' because I want to keep the row where End Su() is written
MsgBox "it begins at " & Start & " and finishes at " & TheEnd
MsgBox "First row to squeeze is " & TargettedFirstRow & " and last row to squeeze is " & TargettedLastRow
.deleteLines TargettedFirstRow, TargettedLastRow
' here it creates problem !!!
End With
End Sub