title: Determine if target cell is in table column, by column name
body: <p>I want to run a procedure if the target cell is in specific columns.</p>
  
  <p>I am using column numbers to determine this. If extra columns are added to the table the system falls over.</p>
  
  <p>My code is below;</p>
  
  <ul>
  <li>the column names are a "Activity", "Resources" and "Stakeholders" (in the table"Schedule");</li>
  <li>the columns are 5, 7 and 17, in the line <code>If Target.Column = 5 Or Target.Column = 7 Or Target.Column = 17 Then</code></li>
  </ul>
  
  <pre class="lang-vb prettyprint-override"><code>If Target.Count &gt; 1 Then GoTo exitHandler
  
  On Error Resume Next
  Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
  On Error GoTo exitHandler
  
  If rngDV Is Nothing Then GoTo exitHandler
  
  If Intersect(Target, rngDV) Is Nothing Then
     'do nothing
  Else
      Application.EnableEvents = False
      newVal = Target.Value
      Application.Undo
      oldVal = Target.Value
      Target.Value = newVal
      If Target.Column = 5 Or Target.Column = 7 Or Target.Column = 17 Then
          If oldVal = "" Then
              'do nothing
          Else
              If newVal = "" Then
                  'do nothing
              Else
                  lUsed = InStr(1, oldVal, newVal)
                  If lUsed &gt; 0 Then
                      If Right(oldVal, Len(newVal)) = newVal Then
                          Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
                      Else
                          Target.Value = Replace(oldVal, newVal &amp; ", ", "")
                      End If
                  Else
                      Target.Value = oldVal _
                        &amp; ", " &amp; newVal
                  End If
              End If
          End If
      End If
  End If
  
  exitHandler:
    Application.EnableEvents = True
  </code></pre>