0

Below is the code I was using to set a starting point and end point of rows that needed to be deleted. This section is found a couple hundred times throughout the spread sheet. If I press F8 through the loop its fine. But if I hit F5 it will do a couple on its own before freezing and giving me an error. Is there a better way to do this?

Dim BeginDLT As Range
Dim EndDLT As Range


wbk.Application.Visible = True

'-------Delete Rows from Sheet Table 1---------

 Const strFindStart As String = "Report generated on:*"
 Set BeginDLT = wbk.Sheets("Table 1").Range("A:BU").Find(What:=strFindStart)
 
Const strFindLast As String = "Comments"
 Set EndDLT = wbk.Sheets("Table 1").Range("A:BU").Find(What:=strFindLast)
 
'-----reworking loop-------

Do Until BeginDLT.Row = 0
    If BeginDLT.Row <> 0 Then
        wbk.Sheets("Table 1").Rows(BeginDLT.Row & ":" & EndDLT.Row + 1).EntireRow.Delete
        Set BeginDLT = wbk.Sheets("Table 1").Range("A:BU").Find(What:=strFindStart)
        Set EndDLT = wbk.Sheets("Table 1").Range("A:BU").Find(What:=strFindLast)
    End If
Loop
Masoud Keshavarz
  • 2,166
  • 9
  • 36
  • 48

0 Answers0