+ Reply to Thread
Results 1 to 12 of 12

Macro to copy data from one excel work book and pase it in another

  1. #1
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Macro to copy data from one excel work book and pase it in another

    Hi

    I have Excel workbook (Data) and another workbook (Result).
    Data workbook contains names and value for example:

    ColumnA , ColumnB
    Names , values
    Apple01, 10
    Apple20, 20
    Orange01,30
    Orange50,30
    Orange, 45
    Apple , 47

    I need to write a macro which gives me a button and when I press it, it copies data from ColumnA where Name field contains any numeric value , as above it should only select Apple01,Apple20,Orange01 and Orange50
    with their values and paste it in Workbook (Result).

    Thanks for your help.

    James

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro to copy data from one excel work book and pase it in another

    Here, try this:

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Macro to copy data from one excel work book and pase it in another

    Maybe?
    Please Login or Register  to view this content.
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  4. #4
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy data from one excel work book and pase it in another

    Hi

    Thanks so much guys. Stupid question probably , how to copy pase this macro in excel . second do I need to do this coding in DATA workbook or RESULTS workbook. Also do I need to keep both these workbook in same directory.

    Thanks

    James

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Macro to copy data from one excel work book and pase it in another

    those are sheets in your workbook, not a different workbooks.

    Check here how to add macro: http://office.microsoft.com/en-us/ex...005204711.aspx

  6. #6
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy data from one excel work book and pase it in another

    Hi

    Sorry maybe I was not very clear earlier. I have two excel workbook(DATA.xlsx and Result.xlsx). They are not two sheets in one workbook. One excel file contains records which I need to select only those records which has numeric value in name column and paste in another excel file ( RESULT.xlsx).
    This mechanism should be triggered when I press Button in RESULT.xlsx .

    Hope it helps you . I am novice to visual basic or vb script. Your help is much appreciated.

    Thanks

    James

  7. #7
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Macro to copy data from one excel work book and pase it in another

    Hi,

    Try This: Post back any issues.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy data from one excel work book and pase it in another

    Thanks for your reply.

    I created a button on Result.xlsx workbook. Double clicked on the button and pasted your code. While I try to run it says "Run-Time error 9: Subscript out of range" when I press debug it highlights following line

    Please Login or Register  to view this content.
    Thanks

    James

    Following is the code

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 05-17-2011 at 11:46 AM. Reason: tidying thread

  9. #9
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Macro to copy data from one excel work book and pase it in another

    Hi,

    I'll try and get a mod to clean up this thread,But your last post is the correct way to post with tags. You should have edited your post that didn't have tags and just add them in and save.

    However your on the right track now. Thank You...

    So here is the problem you pasted the code in your results book.
    The code above should be put in your data workbook with the button on the data page.

    However use this code instead if the button is on your Results workbook and the first worksheet in the workbook.

    Keep me posted...

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy data from one excel work book and pase it in another

    Hi
    Thank you Master!!!. Its working great...
    Only change I had to make was on this line of code
    Please Login or Register  to view this content.
    I see from your code if numeric value appears at the end of string and its two digit long , it gets selected. How difficult is to look for any numeric value in a string and if its find one , copy and paste it on Results.xlsx file.

    Many thanks

    James

  11. #11
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Macro to copy data from one excel work book and pase it in another

    Hi,

    Maybe? Not the best but it appears to work on your data set.

    Let me know.

    Please Login or Register  to view this content.
    .

  12. #12
    Registered User
    Join Date
    05-17-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    6

    Thumbs up Re: Macro to copy data from one excel work book and pase it in another

    Many Thanks for your help. Work great !!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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