title: Are you able to have sheets with the same name but in different workbooks in excel VBA code?
body: <p>My problem is that I have a template file (Monthly Report)  with 455 lines and a DataDownload file where the number of lines varies. When there is no data for a region and a segment it is left out. In all other respects the two files are the same. i.e. Sheet names are the same. My code below is just overwriting the information in the template from the DataDownload. </p>
  
  <pre><code>Option Explicit
  Sub copyanpaste()
  Dim linecount As Long
  Dim linecount2 As Long
  Dim ws As Worksheet
  Dim ws2 As Worksheet
  Dim wb As Workbook
  Dim wb2 As Workbook
  Dim region As String
  Dim region2 As String
  Dim segment As String
  Dim segment2 As String
  Dim i As Long
  Set ws = Worksheets("3 REGION SEGMENT")
  Set ws2 = Worksheets("3 REGION SEGMENT")
  Set wb = Application.Workbooks("DataDownload")
  Set wb2 = Application.Workbooks("Monthly Report - 201705")
  linecount = 4
  linecount2 = 4
  For i = 1 To 455
  With wb
  With ws
  region = ws.Cells(linecount, "B")
  segment = ws.Cells(linecount, "D")
  End With
  End With
  With wb2
  With ws2
  
  region2 = ws2.Cells(linecount2, "B")
  segment2 = ws2.Cells(linecount2, "D")
  End With
  End With
  If region = region2 And segment = segment2 Then
  wb.Sheets("3 REGION SEGMENT").Cells(linecount2, "A").EntireRow.Copy   Destination:=wb2.Sheets("3 REGION SEGMENT").Range("A" &amp; linecount)
  linecount = linecount + 1
  linecount2 = linecount2 + 1
  Else
  linecount2 = linecount2 + 1
  End If
  Next i
  End Sub
  </code></pre>