title: Copying Data to another workbook
body: <p>I use two workbooks (obviously based on the question:)), from the first one (as you will see in the code below) gets sorted by the data in column "B". The data in this column is just a number based on the month (11=November, December=12, etc.). For this question (and it will provide the answer for my other monthly workbooks),  need to copy all the rows of data (columns A:AE) in column B to another workbook (which is already open), and paste the data into the empty row at the bottom. I have the sort part working fine. I am trying to add in the copy &amp; paste function into the code, but can't get it to work. HELP!</p>
  
  <p>Here is the code I have tried (but can't figure out how to get focus to the target workbook):</p>
  
  <pre><code>Sub Extract_Sort_1512_December()
  ' This line renames the worksheet to "Extract"
  Application.ScreenUpdating = False
      ActiveSheet.Name = "Extract"
  
  ' This line autofits the columns C, D, O, and P
      Range("C:C,D:D,O:O,P:P").Columns.AutoFit
  
  ' This unhides any hidden rows
      Cells.EntireRow.Hidden = False
  
  Dim LR As Long
  
  With ActiveWorkbook.Worksheets("Extract").Sort
      With .SortFields
          .Clear
          .Add Key:=Range("B2:B2000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
  
      End With
      .SetRange Range("A2:Z2000")
      .Apply
  End With
  
      For LR = Range("B" &amp; Rows.Count).End(xlUp).Row To 2 Step -1
          If Range("B" &amp; LR).Value &lt;&gt; "12" Then
              Rows(LR).EntireRow.Hidden = True
          End If
      Next LR
  
  Cells.WrapText = False
  Sheets("Extract").Range("A2").Select
  
  Dim LastRow As Integer, i As Integer, erow As Integer
  LastRow = ActiveSheet.Range(“A” &amp; Rows.Count).End(xlUp).Row
  
      For i = 2 To LastRow
          If Cells(i, 2) = “12” Then
          Range(Cells(i, 1), Cells(i, 31)).Select
          Selection.Copy
  
          ActiveWorkbook(“Master File - Swivel - December 2015.xlsm”).Select
          Worksheets(“Master”).Select
          erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
  
          ActiveSheet.Cells(erow, 1).Select
          ActiveSheet.Paste
          End If
      Next i
  
  Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>I have found this code below, but do not know how to insert it properly into my code above. The thing that makes me weary is that the workbooks are already open. The target workbook is located on our SharePoint site and I do not know how (or if) you can use VBA code to open it to your desktop.</p>
  
  <p>Here is the other code:</p>
  
  <pre><code>Sub Demo()
  
      Dim wbSource As Workbook
      Dim wbTarget As Workbook
  
      ' First open both workbooks :
      Set wbSource = Workbooks.Open("  ") ' &lt;&lt;&lt; path to source workbook
      Set wbTarget = ActiveWorkbook ' Workbooks.Open("  ") ' &lt;&lt;&lt; path to destination workbook
  
      'Now, transfer values from wbSource to wbTarget:
      wbTarget.Sheets("Sheet1").Range("B2").Value = wbSource.Sheets("Sheet3").Range("H4")
      wbTarget.Sheets("Sheet1").Range("B3").Value = wbSource.Sheets("Sheet3").Range("J10")
  
      'Close source:
      wbSource.Close
  
  End Sub
  </code></pre>