Find part of string & delete row

L

Les Stout

Hi all, use the code below to find "Total" to delete the row, Total is
part of the string & i am not sure how to change the code to find
"Total" even if it is part of a string ?

Sub DeleteTotalSuppSAP()
'
'
Dim i As Long
Dim iLastRow As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 1 Step -1
If InStr(1, Cells(i, "G").Value, "total", vbTextCompare) Then
Rows(i).Delete
End If
Next i
End Sub

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
 
T

Tom Ogilvy

You code you show identifies cells in column G that contain the substring
total in any case (upper, lower, mixed).

so your code doesn't need to be changed.
 
D

Dave Peterson

Maybe you shouldn't be basing the lastrow on column A:

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row

maybe...

iLastRow = Cells(Rows.Count, "G").End(xlUp).Row

If column A ended in row 11, you'd only be looking at rows 1:11.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top