C
Chris Salcedo
Hi guys,
I have the following code that cleans up a text imported file.
All it does is get rid of lines that contain the find criteria.
This works great but its slow (62k lines in the file and lots of
instances of the crap lines)
Sub DeleteUnwantedLines()
Application.ScreenUpdating = False
Dim lastcell As Range, FoundCell As Range
Do
Set FoundCell = Cells.Find(What:="severn", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="Cost", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="----", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="Actual", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="ERP ", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Call DeleteUnused
Application.ScreenUpdating = True
End Sub
Anyone have any ideas how to do this faster ???
I have another piece of ugly code that also works but is slow.
This checks to see if all values of row x columns B-G are 0 and if so
delete the entire row.
Sub Delete0ValueRows()
ris = mrows
Application.ScreenUpdating = False
Do While ris <> 0
If Range("B" & ris).Value = "0" And Range("C" & ris).Value =
"0" And _
Range("D" & ris).Value = "0" And Range("E" & ris).Value = "0"
And _
Range("F" & ris).Value = "0" And Range("G" & ris).Value = "0"
Then
Range("A" & ris).EntireRow.Delete
End If
ris = ris - 1
Loop
Call DeleteUnused
Application.ScreenUpdating = True
End Sub
Thanks for the help...
I have the following code that cleans up a text imported file.
All it does is get rid of lines that contain the find criteria.
This works great but its slow (62k lines in the file and lots of
instances of the crap lines)
Sub DeleteUnwantedLines()
Application.ScreenUpdating = False
Dim lastcell As Range, FoundCell As Range
Do
Set FoundCell = Cells.Find(What:="severn", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="Cost", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="----", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="Actual", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Do
Set FoundCell = Cells.Find(What:="ERP ", LookAt:=xlPart)
If Not FoundCell Is Nothing Then
Range(FoundCell.Address).EntireRow.Delete
Else
Exit Do
End If
Loop
Call DeleteUnused
Application.ScreenUpdating = True
End Sub
Anyone have any ideas how to do this faster ???
I have another piece of ugly code that also works but is slow.
This checks to see if all values of row x columns B-G are 0 and if so
delete the entire row.
Sub Delete0ValueRows()
ris = mrows
Application.ScreenUpdating = False
Do While ris <> 0
If Range("B" & ris).Value = "0" And Range("C" & ris).Value =
"0" And _
Range("D" & ris).Value = "0" And Range("E" & ris).Value = "0"
And _
Range("F" & ris).Value = "0" And Range("G" & ris).Value = "0"
Then
Range("A" & ris).EntireRow.Delete
End If
ris = ris - 1
Loop
Call DeleteUnused
Application.ScreenUpdating = True
End Sub
Thanks for the help...