Newb: Asking about a tweak in code

  • Thread starter Thread starter menken.john
  • Start date Start date
M

menken.john

I found this code on a VBA site called rondebruin and it works fine but I'mwondering about a tweak that would make it work better with my specific application. The code below goes down through column A and deletes the entirerow for any instance of "ron" that it finds in column A. My question: "Howcould I tweak it so that it deletes rows with any variation of ron like "Devron" or "Ronald?"
Thanks very much.


<code>

Sub Loop_Example()
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

'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet

'We select the sheet so we can change the window view
.Select

'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False

'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1

'We check the values in the A column in this example
With .Cells(Lrow, "A")

If Not IsError(.Value) Then

If .Value = "ron" Then .EntireRow.Delete
'This will delete each row with the Value "ron"
'in Column A, case sensitive.

End If

End With

Next Lrow

End With

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

End Sub

</code>
 
Hi,

Am Mon, 26 Nov 2012 11:56:35 -0800 (PST) schrieb (e-mail address removed):
For Lrow = Lastrow To Firstrow Step -1

'We check the values in the A column in this example
With .Cells(Lrow, "A")

If Not IsError(.Value) Then

If .Value = "ron" Then .EntireRow.Delete
'This will delete each row with the Value "ron"
'in Column A, case sensitive.

End If

End With

Next Lrow

change the code above to:

For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "A")
If InStr(LCase(.Value), "ron") Then .EntireRow.Delete
End With
Next Lrow


Regards
Claus Busch
 
Back
Top