# Delete multiple columns with Criteria

#### Miya

##### Well-known Member
Hi, i have multiple columns with headers titled Total, i tried using the below code, but only one column with title Total gets deleted, how can i get the code to delete muliple columns?

Hdrs = Array("Total")
For i = LBound(Hdrs) To UBound(Hdrs)
Set Found = .Rows(6).Find(what:=Hdrs(i))
Next i

Last edited:

### Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

#### jbeaucaire

##### Well-known Member
Code:
``````Sub DeleteTotalColumns()
Dim LastColumn As Integer
Dim rngcols As Range, cell As Range

LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

Set rngcols = Range(Cells(1, 1), Cells(1, LastColumn))

For Each cell In rngcols
If cell.Value = "Total" Then
cell.EntireColumn.Delete
End If
Next cell
End Sub``````

Last edited:

#### Miya

##### Well-known Member
Thanks for this, question -is this code flexible, say if i want to add more criteria to the below, then is it simply this?

f cell.Value = "Total","Average" Then

Code:
``````Sub DeleteTotalColumns()
Dim LastColumn As Integer
Dim rngcols As Range, cell As Range

LastColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

Set rngcols = Range(Cells(1, 1), Cells(1, LastColumn))

For Each cell In rngcols
If cell.Value = "Total" Then
cell.EntireColumn.Delete
End If
Next cell
End Sub``````

#### jbeaucaire

##### Well-known Member
You can change the code each time you use it, or add OR commands into it
Code:
``If cell.Value = "Total" Or cell.Value = "Average" Then``

Replies
0
Views
196
Replies
0
Views
194
Replies
1
Views
1K
Replies
8
Views
290
Replies
3
Views
94

1,190,836
Messages
5,983,174
Members
439,825
Latest member

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back