eponcedeleon
New Member
- Joined
- Aug 18, 2023
- Messages
- 5
- Office Version
- 365
- 2021
- Platform
- Windows
I am trying to delete columns that do not have certain names in header.
Thi is my code
Here are the column headers. I only want to keep the columns "Due Date", "Task" and "Contact"
I cant figure out why my code is not working.
Thi is my code
VBA Code:
Sub Delete_Specifc_Column()
Dim LastColumn As Long
LastColumn = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
Dim rng As Range
Set rng = ActiveSheet.UsedRange
Set rng = Range("A1:A" & LastColumn)
For Each cell In rng
abc = cell.Value
If cell.Value2 <> "Due Date" Or cell.Value2 <> "Task " Or cell.Value2 <> "Contact" Then
' MOVE TO NEXT CELL
Else
cell.EntireColumn.Delete
End If
Next
End Sub
Here are the column headers. I only want to keep the columns "Due Date", "Task" and "Contact"
I cant figure out why my code is not working.