+ Reply to Thread
Results 1 to 17 of 17

Macro to copy data to separate excel sheet

  1. #1
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Macro to copy data to separate excel sheet

    Hi

    I am trying to create a macro to copy highlighted data in one excel sheet into the first empty cell down a cloumn in a separate excel sheet.

    I am fairly proficient in using excel (formulas, formating etc) but i am struggling with creating macros to do what i want.

    Any guidance on this issue would be very much appreciated.

    Cheers
    Eric

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    Is the highlighting the result of Conditional Formatting?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Sorry, i didnt phrase my question correctly, it should be 'selected' cells not highlighted.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    You could do it this way:

    Please Login or Register  to view this content.
    Last edited by xladept; 11-23-2012 at 05:19 PM.

  5. #5
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Not quite what i was after.

    I need the cells that i manually select to be copied and pasted into a different excel file (samples_submitted_2012.xlsx![Submitted]) in the first cell down column A that is blank.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    Please Login or Register  to view this content.
    Last edited by xladept; 11-23-2012 at 05:45 PM.

  7. #7
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Ok that works, thankyou very much. Is it possible for this macro to work when the destination workbook (where the values are pasted) is not open?

  8. #8
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    I have worked out how to open a the samples_submitted_2012 workbook when closed, but...if the book is already open is there away of bypassing the first line of code? so i dont re-open it.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    You don't need it to be activated as long as it's open - do you want to close it afterwards?

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Hi Xladept

    I have been working on this VBA script, and i have it working the way i want...except that when the workbooks that i am copying the data into are open the the macro will not recognize this and will try to re-open them, which i dont want.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    "ThisWorkbook" is the one with the code in it - and you're closing it - that's probably your problem. I'll look harder later

    See if this solves your problem:

    Please Login or Register  to view this content.
    Last edited by xladept; 11-24-2012 at 10:26 PM.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    See if this does the trick:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    I am getting the error Method 'Range' of object '_worksheet' failed

    and when i debug, it highlights the code: r = ws.Range("A" & Rows.Count).End(xlUp).Row + 1

  14. #14
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Ok so i got it working, here is the code, dont fully understand why this works and not the last code you posted doesnt?

    Please Login or Register  to view this content.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    I guess it didn't like the reuse of ws???? Glad you got it working!

  16. #16
    Registered User
    Join Date
    11-23-2012
    Location
    Vacnouver, Canada
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to copy data to separate excel sheet

    Thanks alot for your help on this Xladept.

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to copy data to separate excel sheet

    You're welcome!

+ 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