title: VBA "Invalid Procedure Call or Argument" Error when extracting text before comma
body: <p>I am receiving &quot;Error 5&quot; when trying to execute below code. Aim is to extract all characters before comma in a cell and then paste them to another cell based on the if statement. I am sure the last line causes the problem but I am not sure why.</p>
  <pre><code>Dim r As Long, commapos As Long, m As Long
  
  m = ActiveSheet.Cells(Rows.count, &quot;A&quot;).End(xlUp).Row
  
  
  For r = 2 To m
  
          If Cells(r, 16).Value &lt;&gt; &quot;0&quot; And Cells(r, 9).Value = &quot;&quot; Then
          commapos = InStr(1, Cells(r, 8), &quot;,&quot;)
          Cells(r, 9).Value = Left(Cells(r, 8), commapos - 1)
      
      End If
      
  Next r
        End Sub
  </code></pre>