Stuck with multiple conditions and comparing strings
<p>I have code which creates a summary table from a bunch of excel files. The code copies and uses xlPasteSpecialOperationAdd to paste the selected range from each files to a temporary sheet.</p>

<p>The summary table has 2 input cells which determines the conditions. The 1st cell contains the statuses which can be [ALL, 0,1,2,3,4,5]. The 2nd field is the date in yyyy/mm/dd format.</p>

<p>The first cell recommended to fill, the second is optional. If the 2nd cell is empty then the date is doesn’t matter.</p>

<p>I think I have some trouble comparing the dates or probably the conditions incorrect. For comparing the dates I used two functions: LIKE and StrComp, but none of them worked or maybe because of the incorrect condition.
Please help me how to fix this code:</p>

<p>Set input cell text to string variable (2016.07 = 7 chars with dots):</p>

<pre><code>'Get input date as string
  AstrDate = OutputWs.Range("P5").Text
'Set the date to year and month format
  AstrDateChars = Left$(strDate, 7)
</code></pre>

<p>Decide if the cell is blank:</p>

<pre><code>'if the input range is blank then rangeBlank is true
  If IsEmpty(OutputWs.Range("P5")) = True Then
    rangeBlank = True
  Else
    rangeBlank = False
  End If


'Get the output date to compare with
BstrDate = oNewBook.Sheets(1).Range("R22").Text
</code></pre>

<p>Get the output value:</p>

<pre><code>'Set the compared date to year and month format
BstrDateChars = Left$(strDate, 7)
</code></pre>

<p>Comparing with StrComp function and store value into a boolean variable:</p>

<pre><code>'compare date strings
'compareResult = StrComp(AstrDateChars, BstrDateChars, vbBinaryCompare)
</code></pre>

<p>Comparing with Like function:</p>

<pre><code>compareResult = AstrDateChars Like BstrDateChars
</code></pre>

<p>The conditions:</p>

<pre><code>'Which IL status you want to copy?
If inputValue = "ALL" And rangeBlank = True Then                                                   'Search for all IL status
    oNewBook.Worksheets(1).Range("G25:N28").Copy
    tempWS.Range("G25:N28").PasteSpecial Paste:=xlPasteAll, operation:=xlPasteSpecialOperationAdd
    oNewBook.Close
ElseIf inputValue = outputValue And rangeBlank = True Then                                         'Search for only the selected IL status
    oNewBook.Worksheets(1).Range("G25:N28").Copy
    tempWS.Range("G25:N28").PasteSpecial Paste:=xlPasteAll, operation:=xlPasteSpecialOperationAdd
    oNewBook.Close


ElseIf inputValue = "ALL" And rangeBlank = False And compareResult = True Then                            'Searcg ALL IL status and date
    oNewBook.Worksheets(1).Range("G25:N28").Copy
    tempWS.Range("G25:N28").PasteSpecial Paste:=xlPasteAll, operation:=xlPasteSpecialOperationAdd
    oNewBook.Close
ElseIf inputValue = "ALL" And rangeBlank = False And compareResult = False Then                           'Searcg ALL IL status and date, If date does not match, then closes the document
    oNewBook.Close


ElseIf inputValue = outputValue And rangeBlank = False And compareResult = True Then                      'Search for the selected IL0-IL5 and date
    oNewBook.Worksheets(1).Range("G25:N28").Copy
    tempWS.Range("G25:N28").PasteSpecial Paste:=xlPasteAll, operation:=xlPasteSpecialOperationAdd
    oNewBook.Close
ElseIf inputValue = outputValue And rangeBlank = False And compareResult = False Then                     'Search for the selected IL0-IL5 and date, if date does not match, then closes the document
    oNewBook.Close
End If
</code></pre>