title: Trying to delete the first sheet in each excel file and then copying from each tab to the master workbook with the same tab names
body: <p>Basically, what my macro is doing right now is going through a folder and picking each excel file and deleting the first tab which is named some_Accounts and then copy pasting data to the master workbook where the worksheet names match. </p>
  
  <p>I am getting an error on
        " If wsDst.Name = wsSrc.Name Then"</p>
  
  <p>Object variable not set or defined. Can someone shed a light on where this is going wrong?</p>
  
  <p>Here is my code</p>
  
  <pre><code>Sub ProjectMacro()
      Dim wbDst As Workbook
      Dim wsDst As Worksheet
      Dim wbSrc As Workbook
      Dim wsSrc As Worksheet
      Dim MyPath As String
      Dim strFilename As String
      Dim lLastRow As Long
      Dim LC As Long
      Dim s As Worksheet, t As String
      Dim i As Long, K As Long
      K = Sheets.Count
  
      Application.DisplayAlerts = False
      Application.EnableEvents = False
      Application.ScreenUpdating = False
  
      Set wbDst = ThisWorkbook
      MyPath = "C:\Users\Adam\Desktop\some files\"
      strFilename = Dir(MyPath &amp; "*.xls*", vbNormal)
  
      Do While strFilename &lt;&gt; ""
  
          Set wbSrc = Workbooks.Open(MyPath &amp; strFilename)
  
          'loop through each worksheet in the source file
          For Each wsSrc In wbSrc.Worksheets
              'Find the corresponding worksheet in the destination with the same 
              name as the source
  
              For i = K To 1 Step -1
                  t = Sheets(i).Name
                  If t = "some_Accounts" Then
                      Application.DisplayAlerts = False
                      Sheets(i).Delete
                      Application.DisplayAlerts = True
                  End If
              Next i
  
              On Error Resume Next
  
              Set wsDst = wbDst.Worksheets(wsSrc.Name)
  
              On Error GoTo 0
  
              If wsDst.Name = wsSrc.Name Then
                  lLastRow = wsDst.UsedRange.Rows(wsDst.UsedRange.Rows.Count).Row + 1
                  wsSrc.UsedRange.Copy
                  wsDst.Range("A" &amp; lLastRow).PasteSpecial xlPasteValues
              End If
          Next wsSrc
  
          wbSrc.Close False
          strFilename = Dir()
      Loop
  
      Application.DisplayAlerts = True
      Application.EnableEvents = True
      Application.ScreenUpdating = True
  End Sub
  </code></pre>