If command with 3 options

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
After learning how to use the debug to see my what the variables are set too
and stepping through it, the problem seems to be with:

iRow = Application.Match(cell.Value, Sheets("List").Range("$A:$A"), 0)

iRow never changes from equaling 0, so it just deletes every column. The
NULL and "Total" arguments seem to work fine.
 
Back
Top