title: VBA - Why is excel closing when running this code for copy/paste data into multiple sheets?
body: <p>Good Day!I have this below VBA code which I'm trying to copy the data from multiple workbooks (XLSX and XLSM) and paste it into multiple sheets into my MasterFile. The problem is that when I am executing the VBA code my excel suddenly stop and exit. See my code below. Thank you!</p>
  
  <pre><code>Public Sub Data()
  Dim wbk As Workbook
  Dim Filename As String
  Dim Path As String
  Dim sht, msht As Worksheet
  Dim lRowFile, lRowMaster As Long
  Dim FirstDataSet As Integer
  
  On Error Resume Next
  
  Path = "C:\Users\VBA\" ' &lt;--- The last d-quote " added by edit - A.S.H
  FirstDataSet = 2 'First Data Set in File
  
  'First Workbook  
  Filename = "Brand1.xlsx"
  
  Set wbk = Workbooks.Open(Path &amp; Filename)
  Set sht = Workbooks(Filename).Worksheets("Raw") 'First Sheet in File
  Set msht = ThisWorkbook.Worksheets("BSM") 'First Sheet in Master
  
  lrF = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 'Last Row in File
  lRM = msht.Cells(Rows.Count, 2).End(xlUp).Row 'Last Row in Master
  
  For i = FirstDataSet To lrF
      lRM = msht.Cells(Rows.Count, 2).End(xlUp).Row 'Last Row in Master
      msht.Range("B" &amp; lRM + 1).Value = sht.Range("A" &amp; i).Value 'ID
      msht.Range("C" &amp; lRM + 1).Value = sht.Range("B" &amp; i).Value 'Name
      msht.Range("E" &amp; lRM + 1).Value = sht.Range("C" &amp; i).Value 'Store
      msht.Range("F" &amp; lRM + 1).Value = sht.Range("D" &amp; i).Value 'Product Code
      msht.Range("I" &amp; lRM + 1).Value = sht.Range("F" &amp; i).Value 'Brand
      msht.Range("J" &amp; lRM + 1).Value = sht.Range("G" &amp; i).Value 'Form
      msht.Range("K" &amp; lRM + 1).Value = sht.Range("H" &amp; i).Value 'Days
      msht.Range("L" &amp; lRM + 1).Value = sht.Range("I" &amp; i).Value 'Category
  Next
      sht.Range("K2:AZZ" &amp; lrF).Copy _
  Destination:=msht.Range("M2")
  wbk.Close True
  
  'Second Workbook
  Filename = "Brand2.xlsm"
  
  Set wbk = Workbooks.Open(Path &amp; Filename)
  Set sht = Workbooks(Filename).Worksheets("Raw") 'First Sheet in File
  Set msht = ThisWorkbook.Worksheets("BSM") 'First Sheet in Master
  
  lrF = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row 'Last Row in File
  lRM = msht.Cells(Rows.Count, 2).End(xlUp).Row 'Last Row in Master
  
  For i = FirstDataSet To lrF
      lRM = msht.Cells(Rows.Count, 2).End(xlUp).Row 'Last Row in Master
      msht.Range("A" &amp; lRM + 1).Value = sht.Range("B" &amp; i).Value 'ID
      msht.Range("G" &amp; lRM + 1).Value = sht.Range("A" &amp; i).Value 'Name
  Next
      sht.Range("C2:AZZ" &amp; lrF).Copy _
  Destination:=msht.Range("N2")
  wbk.Close True
  
  End Sub
  </code></pre>