Delete Columns not Containing Certain Text

D

Dennis

I would like to delete all rows with VBA that DO NOT contain the text TOTAL.
Struuggling some with it so far.

TIA, Dennis
================
 
N

Norman Jones

Hi Dennis,

Try:

Sub Tester()
Dim i As Integer

For i = ActiveSheet.UsedRange.Columns.Count To 1 Step -1
If Application.CountIf(Columns(i), "*Total*") = 0 Then
Columns(i).Delete
End If
Next i

End Sub
 
N

Norman Jones

Hi Dennis,

In case the used range does not start in column A, better would be:

Sub Tester()
Dim i As Integer
Dim j As Integer

With ActiveSheet.UsedRange.Columns
j = .Column + .Count
End With

For i = j - 1 To 1 Step -1
If Application.CountIf(Columns(i), "*Total*") = 0 Then
Columns(i).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