title: Using Split() as NewLine Delimiter VBA
body: <p><strong>INTRODUCTION</strong></p>
  
  <p>I'm trying to delete a line, and if that value from this line is found in the array.</p>
  
  <p>The values are being entered into a TextBox on a Userform with each value separated by the <code>NewLine</code> character.</p>
  
  <p>I think I've managed to pinpoint that the logic is faulty in the <code>Split()</code> function. From the research online, I've seen people using...</p>
  
  <pre><code>Split(text, Chr(10))
  Split(text, Chr(16))
  Split(text, vbLf)
  </code></pre>
  
  <p>None of these values (<code>Chr(10)</code>,<code>Chr(16)</code>,<code>vbLf</code>) seem to be working as intended... What seems to be happening is that it will find the <code>NewLine</code> character but it's not removing it from the string and keeping the value when placed into the array.</p>
  
  <p><strong>CODE</strong></p>
  
  <p>Filling in the data...</p>
  
  <pre><code>data() = Split(frmDeleteLines.textData, Chr(10))
  ''''' Also tested Chr(16) and vbLf
  </code></pre>
  
  <p>Deleting the lines...</p>
  
  <pre><code>Private Sub DeleteLines(textArr() As String, column As Long)
  
     Dim LR As Long
  
     LR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
  
     With ActiveSheet
        For i = LR To 3 Step -1
           If Not (SearchArray(.Cells(i, column), textArr())) Then '&lt;--- Call search array
              .Cells(i, column).EntireRow.Delete 'Delete row if found
           End If
        Next i
     End With
  
  End Sub
  </code></pre>
  
  <p>Searching the array with the compared value...</p>
  
  <pre><code>Private Function SearchArray(searchValue As String, textArr() As String) As Boolean
  
     SearchArray = False
  
     For i = LBound(textArr()) To UBound(textArr())
        Debug.Print "Comparing: "
        Debug.Print "   ARR: " &amp; textArr(i)
        Debug.Print "   VAL: " &amp; searchValue
        If (searchValue = textArr(i)) Then
           SearchArray = True
           Debug.Print "       DONT DELETE!!!!!"
           Exit For
        End If
     Next i
  
  End Function
  </code></pre>
  
  <p>The <code>Debug.Print</code> were for debugging purposes and that's what made me believe the <code>Split()</code> function wasn't doing as intended... To my understand the delimiter in the <code>Split()</code> function will not be included in the array it's being placed in. Maybe there's something more to it for the <code>NewLine</code> value?</p>
  
  <p><strong>INPUT</strong></p>
  
  <pre><code>123456
  789456
  456123
  456789
  </code></pre>
  
  <p><strong>COMPARED VALUES</strong></p>
  
  <pre><code> |_____A____|_____B____|_____C____|
  1|  123456  |   BLAH   |   BLAH   |
  2|  487964  |   BLAH   |   BLAH   |
  3|  456123  |   BLAH   |   BLAH   |
  4|  753496  |   BLAH   |   BLAH   |
  </code></pre>
  
  <p><strong>FINAL RESULT</strong></p>
  
  <pre><code> |_____A____|_____B____|_____C____|
  1|  123456  |   BLAH   |   BLAH   |
  2|          |          |          |
  3|          |          |          |
  4|          |          |          |
  </code></pre>
  
  <p>In theory it should be keeping rows <code>1</code> and <code>3</code> but it's deleting all of them...</p>
  
  <p>When I viewed the immediate window, I noticed that the values being output were as follows...</p>
  
  <pre><code>Comparing: 
     ARR: 123456
     VAL: 123456
  Comparing: 
     ARR: 789456
  
     VAL: 123456
  Comparing: 
     ARR: 456123
  
     VAL: 123456
  Comparing: 
     ARR: 456789
     VAL: 123456
  </code></pre>
  
  <p><strong>QUESTION AT HAND</strong></p>
  
  <p>Is it my logic that is incorrect? Or is there something funky going on with the <code>Split()</code> function in conjunction with the <code>NewLine</code> value?</p>