+ Reply to Thread
Results 1 to 10 of 10

Macro to copy row to specific sheet in closed workbook

  1. #1
    Registered User
    Join Date
    07-03-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Macro to copy row to specific sheet in closed workbook

    I have a spreadsheet with values in columns A-F.

    In column A is a closed workbook name/directory path.
    In column B is the sheet name within the workbook specified in column A.

    I need a macro which will run with a SUBMIT button in column G which will write all row values in columns C-F to a new row in the worksheet specified by A and B. Any further additions should be added to the next available row in the specific worksheet without overwriting previous data.

    Thanks
    Phill

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy row to specific sheet in closed workbook

    Hi,

    is it allowed to open the workbook with vba and then close it again or is it used by another user?
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    07-03-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to copy row to specific sheet in closed workbook

    Thank you for the reply. The workbook can be opened and closed (if this is done immediately), but preferably it would be done without opening and closing.
    Also is there any way of deleting the row from the original sheet once it has been copied to the new sheet so that fresh data can be added?

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy row to specific sheet in closed workbook

    Hi,

    try these 2 files: Source.xlsm Target.xlsx

    source contains:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-03-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to copy row to specific sheet in closed workbook

    Thanks, but it doesn't seem to write to the Target workbook? I click submit, but the data disappears from the Source workbook, but isn't on the Target.

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy row to specific sheet in closed workbook

    Hi,

    did you experience that with the sample files with nothing changed except the filepath in source A1? very strange

  7. #7
    Registered User
    Join Date
    07-03-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to copy row to specific sheet in closed workbook

    Yes, I didn't change anything other than the file path to suit my PC, click submit, it deleted data in Source, and Target was unchanged.

  8. #8
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy row to specific sheet in closed workbook

    Remove the code from the source and use this instead, the cells will not be cleared and the target will not be closed, inform me about any pop-ups or errors/crashes. We will implement everything back if we find out were the problem is.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-03-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to copy row to specific sheet in closed workbook

    Thanks for the update.

    Cells C3-F4 are selected in the target file (this was happening before also).

    The source rows aren't deleting, however the target file remains unchanged when the submit button is clicked. I also tried adding data to the source file in row 10, clicked submit, and again no change to the target file.

    If it's easier, we can limit the input of one row at a time before clicking submit. Ideally we would want the source row to be deleted once it's been transferred to target.

  10. #10
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Macro to copy row to specific sheet in closed workbook

    replace the if block with the following and run
    Please Login or Register  to view this content.
    we expect a messagebox to appear 2 times

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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