title: Code to perform formulas to all excel files in a folder not running?
body: <p>=I have a code that performs a series of calculations to all Excel (.xls) files in a folder destination and places a specific number in specified cells (G2, H2, I2, M2 and O1). The only issue is the code does not respond when I click run. It doesn't give an error. Any ideas where I went wrong here?</p>
  
  <pre><code>Sub Code()
  
      Dim file As String
      Dim wbResults As Workbook
      Dim i As Long
      Dim myPath As String
  
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
  
      myPath = "C:\Location\"
  
      file = Dir$(myPath &amp; "*.xls*")
  
      While (Len(file) &gt; 0)
          Set wbResults = Workbooks.Open(Filename:=myPath &amp; file, UpdateLinks:=0)
  
          With wbResults.Worksheets(Split(file, ".")(0))
              i = .Cells(.Rows.Count, 2).End(xlUp).Row
  
              With .Range("G2")
                  .Formula = "=0"
              End With
  
              With .Range("G3:G" &amp; i)
                  .Formula = "=SQRT(((E3-E2)^2)+((F3-F2)^2))"
              End With
  
              With .Range("H2")
                  .Formula = "=1"
              End With
  
              With .Range("H3:H" &amp; i)
                  .Formula = "=G3+H2"
              End With
  
              With .Range("I2")
                  .Formula = "=1"
              End With
  
              With .Range("I3")
                  .Formula = "=IF(D3&gt;=SUM($I$2:I2*2.5+$O$1),1,0)"
              End With
  
              With .Range("I4:I" &amp; i)
                  .Formula = "=IF(D3&gt;=SUM($I$3:I3)*2.5+$O$1,1,0)"
              End With
  
              With .Range("J2:K" &amp; i)
                  .Formula = "=IF($I2=1,D2,J1)"
              End With
  
              With .Range("K2:K" &amp; i)
                  .Formula = "=IF($I2=1,H2,K1)"
              End With
  
              With .Range("L2:L" &amp; i)
                  .Formula = "=IF(I2=1,(J2-J1)/(K2-K1),"")"
              End With
  
              With .Range("M2")
                  .Formula = "=0"
              End With
  
              With .Range("M3:M" &amp; i)
                  .Formula = "=IF(L3="",M2,L3)"
              End With
  
              With .Range("O1")
                  .Formula = "=177.5"
              End With
  
          End With
  
          wbResults.Close SaveChanges:=True
          file = Dir
      Wend
  
      Application.DisplayAlerts = True
      Application.ScreenUpdating = True
  End Sub
  </code></pre>