View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zarlot531 Zarlot531 is offline
external usenet poster
 
Posts: 11
Default Deleting rows based on data NOT meeting criteria --working macro here, just need help with tweaking

Here is the model of the code I'm using -- this come from
http://www.rondebruin.nl/delete.htm

Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1

With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1

If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in
the cell

ElseIf .Cells(Lrow, "A").Value = "ron"
Then .Rows(Lrow).Delete
'This will delete each row with the Value "ron" in
Column A, case sensitive.

End If
Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub

__________________________________________________ __

Here is my situation and my questions:

In Column A on my spreadsheet, there is data like this:


AR3303
AR4055
Subtotal
Blank Cell (and row)
Blank Cell (and row)
AR9999
DP3838
DP3923
DP3932


What I want to do is delete all rows that do NOT contain the DP in the
first cell (Column A cell). I think I could do this somehow using a
LEFT function and obviously an IF NOT function somehow, but I'm having
problems tweaking it to do it this way.

Can anybody help?