title: How can I delete a file based on cell value?
body: <p>I'm having trouble deleting a file based on cell value.
  I get an error message on the line with the Kill command below:</p>
  
  <pre><code>Kill path &amp; r.Offset(1, -4) &amp; "\" &amp; r.Offset(1, -3)
  </code></pre>
  
  <p>Any ideas?</p>
  
  <pre><code>Sub INACTIVE_files()
  
      Const path = "C:\Users\NikolouzosD\AppData\Local\Temp\vbakillfunction\"
  
      Dim r As Range
      Dim x As Integer
  
      Set r = Cells(1, 5)
      Do Until r = ""
          If UCase(r.value) = "INACTIVE" Then
  
              Kill path &amp; r.Offset(1, -4) &amp; "\" &amp; r.Offset(1, -3)
            End If
            Set r = r.Offset(1, 0)
      Loop
  
  End Sub
  </code></pre>
  
  <p>The code starts from cell E1 and looks for INACTIVE files in the same column, until there's no more files to look for.
  Then, it checks the folder name (Column A), combines it with the Cube (Column B)
  and puts both of them in a path:</p>
  
  <pre><code>path = "C:\Users\NikolouzosD\AppData\Local\Temp\vbakillfunction\"
  </code></pre>
  
  <p>so for example:
  for cell E2 which is INACTIVE, the path should be:</p>
  
  <pre><code>C:\Users\NikolouzosD\AppData\Local\Temp\vbakillfunction\WPO 17 02 04 3MMT All Periods\BG023104.txt
  </code></pre>
  
  <p>It then deletes the INACTIVE files (Cubes) from the appropriate folder.</p>
  
  <p><img src="https://i.stack.imgur.com/GbmFE.jpg" alt="enter image description here"></p>