Macro analyses Cell . If text found , delets entire row

A

andrei

I have a table with many columns and rows . Tha Macro should search if cells
from C column contain text . If yes , it delets entire row .
 
G

Gary''s Student

Something like this:

Sub rowkiller()
Dim s As String, n As Long, i As Long
s = "text"
n = Cells(Rows.Count, 3).End(xlUp).Row
For i = n To 1 Step -1
If InStr(Cells(i, 3).Value, s) > 0 Then
Rows(i).Delete
End If
Next
End Sub
 
O

Otto Moehrbach

I didn't take your "text" to mean the word "text". I think you meant any
text not including a numeric entry. The following macro will do what you
want. HTH Otto
Sub DelCText()
Dim rColC As Range
Dim c As Long
Set rColC = Range("C2", Range("C" & Rows.Count).End(xlUp))
For c = rColC(rColC.Count) To 1 Step -1
If rColC(c) <> "" And _
Not IsNumeric(rColC(c)) Then _
rColC(c).EntireRow.Delete
Next c
End Sub
 
A

andrei

Yep , i meant any text not including numeric entry

The macro gives a type mismatch for :
For c = rColC(rColC.Count) To 1 Step -1


@Gary''s Student

I tried your macro , also . But it nothing happens
 
G

Gary''s Student

This version removes rows with any text in column C:

Sub rowkiller2()
Dim n As Long, i As Long
n = Cells(Rows.Count, 3).End(xlUp).Row
For i = n To 1 Step -1
If IsNumeric(Cells(i, 3).Value) Then
Else
Rows(i).Delete
End If
Next
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