title: If Len(Dir(ActualValue)) = 0 Then code excel vba always return true inside for loop
body: <p>I have an excel vba sub which checks if the file is in the said directory or not. The problem is it always goes to File Saved after the first iteration of the for loop. The value of the <code>ActualValue</code> has some in it if the file is actually found, but if it is missing the value is "". The problem is it always go to the = 0 or = "" Condition.</p>
  
  <pre><code>Dim ActualValue As String
  
  For i = 17 To 32
  On Error Resume Next
  
  DateFormat = Format("2017-12-11", "yyyy-mm-dd")
  
  Sheet4.Cells(i, 5).Select
  Selection.ClearContents
  
  SearchValue = Sheet4.Cells(i, 1).Value
  
  If SearchValue = "" Then
      MsgBox "No A/C indicated. Please check.", vbOKOnly
      Exit Sub
  End If
  
  ActualValue = Dir("A:\123 456\789\abc efg\Sample Folder\SAMPLE FOLDER\" &amp; DateFormat &amp; "\" &amp; SearchValue &amp; "" &amp; "*.xls")
  
  If Len(Dir(ActualValue)) = 0 Then
      Sheet4.Cells(i, 10).Value = "File Saved"
  Else
      Sheet4.Cells(i, 10).Value = "File Missing"
      GoTo FileMissing
  End If
  
  FileMissing:
  Next i
  
  Application.ScreenUpdating = True
  End Sub    
  </code></pre>