G
Guest
I am trying to compare a row of names with a column list.
If the name is in the list I want it to go to the next cell.
If the name = NULL then I want it to go to the next cell.
If the name = Total I want it to stop.
If the name is not in the list I want it to delete the column.
Sub NameDelete()
With Sheets("RowOfNames")
For Each cell In .Range("$1:$1")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("List").Range("$A:$A"), 0)
On Error GoTo 0
If cell.Value = Null Then Resume Next
If cell.Value = "Total" Then End
If cell.Value <> iRow Then cell.EntireColumn.Delete
Next cell
End With
End Sub
It runs, but deletes everything.
I copied this code from another answer and tried to adopt it to my project.
Thanks in advance.
If the name is in the list I want it to go to the next cell.
If the name = NULL then I want it to go to the next cell.
If the name = Total I want it to stop.
If the name is not in the list I want it to delete the column.
Sub NameDelete()
With Sheets("RowOfNames")
For Each cell In .Range("$1:$1")
iRow = 0
On Error Resume Next
iRow = Application.Match(cell.Value,
Sheets("List").Range("$A:$A"), 0)
On Error GoTo 0
If cell.Value = Null Then Resume Next
If cell.Value = "Total" Then End
If cell.Value <> iRow Then cell.EntireColumn.Delete
Next cell
End With
End Sub
It runs, but deletes everything.
I copied this code from another answer and tried to adopt it to my project.
Thanks in advance.