title: VBA loop through columns - if inside for
body: <p>What is wrong with this code? It is supposed to return header (1st row) of a column in which it finds "1". I pass the row number (nr) and it is supposed to look between columns M and T (inclusive)</p>
  
  <pre><code>Function who(ByVal rowNr As Integer) As String
      Dim temp As String
      Dim ws As Worksheet
      With ActiveSheet
          Set ws = ActiveWorkbook.Sheets(.Name)
      End With
      For i = 13 To 20 Step 1
          If ws.Cells(i, rowNr).Value = 1 Then
              temp = temp &amp; " " &amp; ws.Cells(i,1).Value
          End If
      Next i
      who = temp
  End Function
  </code></pre>
  
  <p>The error I get is </p>
  
  <blockquote>
    <p>Application-Defined or Object-Defined
    error</p>
  </blockquote>
  
  <p>And marks line </p>
  
  <pre><code>If ws.Cells(i, nr).Value = 1 Then
  </code></pre>
  
  <p>I truly dislike VB.</p>