+ Reply to Thread
Results 1 to 6 of 6

Macro code help - Copy columns to other workbook

  1. #1
    Registered User
    Join Date
    02-06-2023
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Macro code help - Copy columns to other workbook

    Hi Guys,

    Workbooks:
    File 1 - Interviewer_Response_Data-Data_Splitter.xlsm - Contains Macro
    File 2 - Huongs_Dashboard.xls - Data to be pasted here

    Both contain a single worksheet called Raw_Data

    Actions needed:
    1. Macro running in File 1 needs to open File 2
    2. Copy certain columns of data (not headers) from Raw_Data tab.
    3. Paste in File 2 on Raw_Data tab under last data cell
    4. Save and close File 2

    This is the code I have pieced together so far as I am new to this, but it opens File 2 and then does not do anything else, some help would be appreciated

    Sub OpenWorkbook()

    Workbooks.Open "XXXXXXX"

    End Sub

    Sub Copy_Paste_Below_Last_Cell()
    'Find the last used row in both sheets and copy and paste data below existing data.

    Dim wsCopy As Worksheet
    Dim wsDest As Worksheet
    Dim lCopyLastRow As Long
    Dim lDestLastRow As Long

    'Set variables for copy and destination sheets
    Set wsCopy = Workbooks("Interviewer_Response_Data-Data_Splitter.xlsm").Worksheets("Raw_Data")
    Set wsDest = Workbooks("Huongs_Dashboard.xlsx").Worksheets("Raw_Data")

    '1. Find last used row in the copy range based on data in column A
    lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row

    '2. Find first blank row in the destination range based on data in column A
    'Offset property moves down 1 row
    lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Offset(1).Row

    '3. Copy & Paste Data
    wsCopy.Range("A:C,E:F,J:J,M:P,R:T,V:V" & lCopyLastRow).Copy _
    wsDest.Range("A" & lDestLastRow)

    End Sub

    Sub CloseWorkbook()

    Workbooks("Huongs_Dashboard.xls").Close SaveChanges:=True

    End Sub

    Thanks
    Kelem~

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Macro code help - Copy columns to other workbook

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    02-06-2023
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Macro code help - Copy columns to other workbook

    Hi Mumps1,

    Thank you for reviewing, unfortunately it seems to still have issues functioning and throws up an error.

    Seems there is issues with locating the open workbook.

    I have attached the image of error and debugger.

    Thanks
    Kelem~
    Attached Images Attached Images

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Macro code help - Copy columns to other workbook

    Try using the full path. Change to suit your needs.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-06-2023
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Macro code help - Copy columns to other workbook

    Hi Mumps1,

    Thank you for your help an apologies for the delayed response!

    The above didnt work, however I replaced with Windows("Huongs_Dashboard.xlsx").Activate and it works perfectly!

    As the initial call opens the workbook.

    Thank you so much for your help!

    Thanks
    Kelem~

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,052

    Re: Macro code help - Copy columns to other workbook

    You are very welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to copy selected columns into a new workbook
    By manuscriptguru in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-04-2020, 10:36 AM
  2. Replies: 2
    Last Post: 03-18-2017, 02:05 AM
  3. [SOLVED] problems with macro copy columns into another workbook
    By megtoma in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2014, 05:47 PM
  4. [SOLVED] macro to copy columns from one workbook to another
    By megtoma in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-26-2014, 03:22 PM
  5. Macro to copy and paste columns from one workbook to a new workbook
    By windcloud2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2012, 11:45 AM
  6. Need macro to Concatenate columns in one workbook and copy to another workbook
    By capnhud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2010, 05:14 PM
  7. Macro to copy code into another workbook
    By DeckyB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2010, 05:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1