PDA

View Full Version : Delete Columns Based On Text



Justinbodden
09-25-2015, 06:18 AM
Hi All-

I have to run a report every week and there are some columns that I just don't need.

Can someone help me delete any columns that contain the words "sales (qty)" and also columns that contain the words "number of tickets"?

Thanks in advance!

SamT
09-25-2015, 07:52 AM
Those Strings look like Headers. Don't they always appear in the same place?"sales (qty)"

Sub DelColumns()
'Crude and easy to modify
Dim Found As Range

With ActiveSheet.Cells
Set Found = .Find(What:="sales (qty)", After:=Range("A1"), SearchDirection:=xlPrevious)
Do While Not Found Is Nothing
Found.EntireColumn.Delete
Set Found = .FindNext(Found)
Loop

Set Found = .Find(What:="number of tickets", After:=Range("A1"), SearchDirection:=xlPrevious)
Do While Not Found Is Nothing
Found.EntireColumn.Delete
Set Found = .FindNext(Found)
Loop
End With
End Sub