title: Better way to search for date in table and if not found then insert date
body: <p>I wrote the following code to search column A for the date of a document that I am trying to import and if not found then insert a new row and import the data:</p>
  
  <pre><code>' If the document date is earlier than the date in the first line of the spreadsheet search for the date in the A column
  ElseIf strSheetDate &gt; strFileNameDate Then
      Set rngSheetDate = WS1.Range("A:A").Find(strFileNameDate)
  
      ' If the date is found in A column then add the data to that row
      If Not rngSheetDate Is Nothing Then 'when rng &lt;&gt; nothing means found something'
  
          If WS2.Cells(2, 2).Value &lt;&gt; "" Then WS1.Range(rngSheetDate.Address).Offset(0, 1).Value = WS1.Range(rngSheetDate.Address).Offset(0, 1).Value + WS2.Cells(2, 2).Value
          If WS2.Cells(3, 2).Value &lt;&gt; "" Then WS1.Range(rngSheetDate.Address).Offset(0, 3).Value = WS1.Range(rngSheetDate.Address).Offset(0, 3).Value + WS2.Cells(3, 2).Value
  
  
      Else
  
          ' If it is not found then look for dates either side of the document date and then insert a new line for that record
          iRow2 = WS1.Cells(Rows.count, 1).End(xlUp).Row
          Set rngSheetDate2 = WS1.Range("A2:A" &amp; iRow2)
          For Each cell In rngSheetDate2
  
              If cell.Value &gt; strFileNameDate And cell.Offset(1, 0).Value &lt; strFileNameDate Then
  
                  WS1.Range(cell.Offset(1, 0), cell.Offset(1, 4)).Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                  cell.Offset(1, 0).Value = strFileNameDate
  
                  If WS2.Cells(2, 2).Value &lt;&gt; "" Then
                      cell.Offset(1, 1).Value = WS2.Cells(2, 2).Value
                  Else
                      cell.Offset(1, 1).Value = 0
                  End If
  
                  If WS2.Cells(3, 2).Value &lt;&gt; "" Then
                      cell.Offset(1, 3).Value = WS2.Cells(3, 2).Value
                  Else
                      cell.Offset(1, 3).Value = 0
                  End If
  
                  Exit For
  
              End If
          Next
  
      End If                
  End If
  </code></pre>
  
  <p>There must be a better way to search for a string in column 1 of the table and if not found then add a new line in the middle of the table or add to the bottom.</p>
  
  <p>any advice ?</p>