ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Delete Columns not Containing Certain Text (https://www.excelbanter.com/excel-worksheet-functions/7099-delete-columns-not-containing-certain-text.html)

Dennis

Delete Columns not Containing Certain Text
 
I would like to delete all rows with VBA that DO NOT contain the text TOTAL.
Struuggling some with it so far.

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

Dennis

Ooops.... I meant delete all columns, not rows...sorry.

Dennis
====================

In article ,
(Dennis) wrote:
I would like to delete all rows with VBA that DO NOT contain the text TOTAL.
Struuggling some with it so far.

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


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

--

---
Regards,
Norman



"Dennis" wrote in message
m...
Ooops.... I meant delete all columns, not rows...sorry.

Dennis
====================

In article ,

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

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




Dennis

Works perfect, thanx Norm!!!!

Dennis
===================


In article , "Norman Jones"
wrote:
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


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

---
Regards,
Norman



"Dennis" wrote in message
. com...
Works perfect, thanx Norm!!!!

Dennis
===================


In article , "Norman Jones"
wrote:
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





All times are GMT +1. The time now is 03:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com