Deleting rows with wild card

P

parteegolfer

I have this macro I want to delete any row with the first 6 characters
that start with "Inshop" in column (A). there could be other characters
within the cell that contains "Inshop" so I need some sort of wildcard
in the code below. Any suggestions?


Code:
--------------------
Option Explicit

Public Sub DeleteRows()

Const TestColumn As Long = 1
Dim cRows As Long
Dim i As Long

'first, count the rows to operate on
cRows = Cells(Rows.Count, TestColumn).End(xlUp).Row

For i = cRows To 2 Step -1
'check if current row contains Inshop*
If Cells(i, TestColumn).Value = "Inshop*" Then
Cells(i, TestColumn).EntireRow.Delete
End If
Next i

End Sub
 
G

Gary Keramidas

will this do what you want?

Option Explicit
Public Sub DeleteRows()

Const TestColumn As Long = 1
Dim cRows As Long
Dim i As Long

'first, count the rows to operate on
cRows = Cells(Rows.Count, TestColumn).End(xlUp).Row

For i = cRows To 2 Step -1
'check if current row contains Inshop*
If InStr(1, "INSHOP", UCase(Range("a" & i).Value)) = 1 Then
Rows(i).EntireRow.Delete
End If
Next i

End Sub
 

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