+ Reply to Thread
Results 1 to 9 of 9

copy selected data from a workbook to another spreadsheet each time I run a template

  1. #1
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    copy selected data from a workbook to another spreadsheet each time I run a template

    Hello
    It would be great if someone could help me with this. I have no real experience with macros and rely on sites like this to find the code I need. That said I cant find exactly what I'm looking for this time....

    I have an excel template which I use for estimating. I would like to copy selected data from that workbook to another spreadsheet each time I run the template. I have organised the data I want into one row on my template and currently I manually select, copy and paste this into the next available row on a spreadsheet called "Estimate List". I have managed to record a macro to do this but it always overwrites the row which I use when I record the macro. I also have problems with whether the Workbook containing "Estimate list" is open or closed when I try to run the macro.

    Thanks in advance for any suggestions you might have.

    Cheers Mick

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    If you could upload a sample workbook it would make things easier however I can give you a generic guide. The reason you keep overwriting the data with the recorded macro is that you need to find the last row of data on the Estimate Sheet and add 1 to the row number. You can also test to see if the Estimate List workbook is open with this code. I am pasting the data into Sheet1 - you will need to modify to your needs. If this does not help if you upload a sample workbook with no sensitive data and be specific about what you want copied and where you want the data placed I can help you further
    Please Login or Register  to view this content.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  3. #3
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    PV Potential calculator example.xlsm

    Thanks Anthony it helps a lot.
    I'm attaching the template and a Blank version of "Estimate List" When I run your macro it tries to save the template which is open. it selects the data which I want t copy but doesn't open "Estimate List" or attempt to past the data to that book.
    I'm confident that it's something I'm doing wrong so if you can have a look I'd appreciate it. Its not urgent but something I'd like to resolve sometime.
    Thanks Again

    Mick
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    There was a few problems - firstly your workbook Estimate List has a space between the name and the extension i.e. Estimate List .xlsx (notice the space). Secondly I was pasting ALL rather than pasting values as your range set to copy is all formulas - Change Estimate List .xlsx to the REAL filename - I notice you have Estimate List 2012.xlsx in the open workbook command. In your above example is it Estimate List .xlsx ->Make sure that you use the same filename through the code. It should solve your problems.
    Please Login or Register  to view this content.
    Using your above example the attached workbook code is correct just make sure the Estimate List.xlsx file is consistent throughout the code (and watch spaces between filename and extension)

  5. #5
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    Cheers Anthony I've been away so I haven't had a chance to try this yet, I'll let you know how it works.

  6. #6
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    That works a treat now that I've sorted out my dodgy filename's (&Extensions)

    Thanks again

    Mick

  7. #7
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Smile Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    The code you have given me works well but I have tried to change it so that it paste's the data as a link rather than as a value. I've tried the following

    Please Login or Register  to view this content.
    As I said i'm a complete novice at using vba so this is mainly guesswork on my part.

    as ever if you can help it will be appreciated

    regards

    Mick
    Last edited by mickyh; 02-04-2012 at 06:05 AM.

  8. #8
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    Hi Mick
    Is there a reason you want to paste as a link because my understanding is that in the PV Calculator workbook that the data in Range("A34:G34") will change. As a result the data in the Estimate list will change so it will always reflect the data in the Calculator workbook and not necessarily the data that was copied across. Does that make sense? Anyway to paste as a link
    Please Login or Register  to view this content.
    However as I say this will lead to the last rows of data in the Estimate list to be the same value as the current values in the Calculator workbook. It may look like the path to the Calculator workbook does not show in the Formula Bar in the Estimates sheet however once you shut the Calculator workbook the path will show up in the formula bar. The main reason to have links to workbooks is for example a master Price List where you just change the prices in one workbook and this will be reflected in the linked workbook. Anyway see if this is what you are after.

    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated

  9. #9
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    Thanks Anthony
    That is exactly what I wanted. I understand your comments about changing the last row on the log sheet. I use the macro in a template so I'm always starting with the next No invoice etc. Part of the data transferred is the value of the estimate. its not unusual for me to change estimate's a number of times so this way the data on the log sheet should always be correct? I use a button on the template to run the macro and taking your comments on board I have now set it so the button is deleted once it is used once to prevent me accidently clicking on it and adding the data secondly.
    Thanks again for all your help, I included the final code which you might find easier to understand than my ramblings.....
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: copy selected data from a workbook to another spreadsheet each time I run a templ

    Excellent. I am glad you worked it all out. It does make more sense now you explain it.

+ 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