Originally Posted by
jolivanes
That did it Mark. Thanks a million.
One more question if I may. The code is case sensitive so if some are .Xls or .XLS or .DOC etc, they will be deleted also.
How would I make it non case sensitive.
Thanks again Mark.
Note: I don't have to start a new thread for this do I?
Of course you may; we are here to help each other.
You could include:
[vba]Option Compare Text[/vba]
at the top of the module to disclude case sensitivity. I would not, as this affects the entire module.
While technically, it adds to processing (as there is more to do), I would simply have the code compare 'apples to apples':
Sub DelAllButTheseFiles()
Dim _
lLastRow As Long, _
i As Long
Application.ScreenUpdating = False
With ActiveSheet
lLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = lLastRow To 1 Step -1
If LCase(Right(.Cells(i, "A").Value, 4)) <> ".xls" _
And LCase(Right(.Cells(i, "A").Value, 4)) <> ".doc" _
And LCase(Right(.Cells(i, "A").Value, 4)) <> ".txt" _
And LCase(Right(.Cells(i, "A").Value, 4)) <> ".csv" Then
Rows(i).Delete
End If
Next
End With
Application.ScreenUpdating = True
End Sub
Mark