title: Delete whitespaces vba Excel
body: <p>I want to delete all whitespaces in a range and got the following code</p>
  
  <pre><code>Dim rng2 As Range
  Dim cleanString2 As String
  Set rng2 = ContactData.Range("AR2:AR" &amp; lRow)
  rng2.Value = Application.Trim(rng2)
  For j = 2 To lRow
      cleanString2 = ContactData.Range("AR" &amp; j).Value
      cleanString2 = Replace(cleanString2, Chr(10), "")
      ContactData.Range("AR" &amp; j).Value = cleanString2
  Next j
  </code></pre>
  
  <p>I got and equivalent code with same variables and everything just <strong>without</strong> the <strong>2</strong> in the <strong>variable names</strong> the code works, but the other code goes for colum <strong>A</strong> instead of <strong>AR</strong>, can anybody help me with finding the bug?
  <strong>Thanks!</strong></p>
  
  <pre><code>Dim rng As Range
  Dim cleanString As String
  Set rng = ContactData.Range("A2:A" &amp; lRow)
  rng.Value = Application.Trim(rng)
  For i = 2 To lRow
      cleanString = ContactData.Range("A" &amp; i).Value
      cleanString = Replace(cleanString, Chr(10), "")
      ContactData.Range("A" &amp; i).Value = cleanString
  Next i
  </code></pre>
  
  <p>this is the working code, below a picture of the variable values while debugging:</p>
  
  <p><a href="https://i.stack.imgur.com/nsOFv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nsOFv.png" alt="Debugging Code"></a></p>