0

I'm currently trying to copy from one worksheet and paste into a new worksheet using VBA. however i have the following variables

  • The worksheet with data being copied is dynamic. the columns stay the same but the rows change every week.
  • The new worksheet which the data will be added to is dynamic. The Columns are the same but the new worksheet rows increase every week( e.g row 700 one week row 800 the next).
  • The columns (A and BC) that are being copied and pasted are consistent.
  • The data should be pasted on columns A- BC on the next available row of the new worksheet

I've currently managed to come up with the following code but i keep getting error's and don't know where i am going wrong as i am new to VBA.

 Sub CandP()
'
'

Dim Last_Row As Long

Application.ScreenUpdating = False

Last_Row = Range("A2:BC2" & Rows.Count).End(xlUp).Row
Range("A2:BC2").Copy
Windows("Newsheet.xlsm").Activate
Range("$A2:BC$" & last_row).FillDown

End Sub

All help is appreciated, Thank you

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
MCharm88
  • 1
  • 1
  • 1
  • 2
  • you need to reference the other sheet in the other workbook, so it would be like other_workbook.sheet1.range("A2:BC" & last_row).value = Range("$A2:BC$" & last_row).value or something similar. There are many posts on here doing the same thing, and if conditions are met. – Nathan_Sav Jan 05 '16 at 16:05

1 Answers1

3

You could try this:

Option Explicit

    Sub CandP()

    Dim Last_Row1 As Long, Last_Row2 As Long
    Dim WB1 As Workbook, WB2 As Workbook
    Dim ws1 As Worksheet, ws2 As Worksheet

    Set WB1 = ThisWorkbook ' Workbook where you want to copy the data
    Set ws1 = WB1.Sheets("Sheet1") ' Change the name of your Sheet
    Set WB2 = Workbooks.Open("C:\Desktop\vba\Newsheet.xlsm") ' Enter the address of the Workbook you want to paste the data
    Set ws2 = WB2.Sheets("Sheet1") ' Change the name of your Sheet

    Last_Row1 = ws1.Range("A" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
    Last_Row2 = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1 ' Determine the next empty row in order to paste the data

    ws1.Range("A2:BC" & Last_Row1).Copy ws2.Range("A" & Last_Row2)

    End Sub
manu
  • 942
  • 8
  • 17