+ Reply to Thread
Results 1 to 42 of 42

Exporting

  1. #1
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Exporting

    right now this code exports to another sheet, and only exports the active cell. I want to export to a new spreadsheet with a new name, and a given area instead of just the active cell.

    Please Login or Register  to view this content.
    Is it possible to have the new spreadsheet name preset in the code? the space i am looking to export is A4:C34, F4:F34, I4:Q34. I would also like to know if only the data that gets exported, gets exported if a "y" vs "n" is in place in fields F4:F34?
    Last edited by jabryantiii; 01-20-2010 at 01:27 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    Its a bit hard to decypher what you are asking for, but to me it seems like you want to copy certain cells in a row if the value in column F of that row is y. If that is true, this should do it for you:

    Please Login or Register  to view this content.
    If not, could you try explaining it again in some other way?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    I reset the name to AA_Test and i get a debug

    "run time error 1004
    cannot rename a sheet to the same name as another sheet....etc"

    I do not have another AA_Test sheet any where on my pc or network...I have triple checked.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    to try and explain my idea and question a little better....here it goes..

    I have a workbook that is used to keep track of sales made and commssions to be paid or not paid based on a "y" for yes to pay or "n" for not to pay.

    within this workbook, i now have an accounting department that has decieded a year after the fact that they can not read the information the way they want to any longer, there fore instead of rewirting the entire work book i just want to export specific data from it and only that data within a given area based on the "y" vs "n"

    the data i want to export is the same for each spreadsheet with in the workbook as far as placement goes, cells A4:Q34 for January, but i only want to export cells A4:C34, F4:F34, and I4:Q34. To add to this i only want that data with those cells to be exported if there is a "y" in the row of cells F4:F34.

    actually i dont care if there is "y" vs "n"....i just want to export the data from those cells requrdless of a "y" or "n".

  5. #5
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    the end result is to have a new sheet, outside of this workbook, created for each month and each sales person, from the data with the given cell range.
    Last edited by jabryantiii; 01-06-2010 at 02:45 PM.

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    Hmm, I can't understand why that error would appear if you don't have a sheet with that name already in that workbook. Can you try changing the name in the code and running again?

  7. #7
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    changed the name, same result, and then i noticed why...i made the grand leap into thinking that the new sheet would be created outside of the workbook but it was creating them within the same workbook. I feel kinda dumb as well i should for not paying attention to my enviroment.

    the other thing i noticed is that it is creating the entire spreadsheet and not the cell range of that sheet. this in turn is a nice feature when i need to create new sheets based off of a master sheet. something i will definitly hold onto for future use.

    in the mean time i am still stuck on exporting just the cell range of A4:Q34..not the entire sheet.

    durning lunch i wa trying to work it out in my head, so that my explanation would make more sense. food helps the brain work it turns out....

    so this is what i have come up with for an explanation, i have 16 (+/-) sales people per year, each sales person has their own sheet in the workbook. each sheet is broken down veritically by month, starting with January, each month takes up 30 rows. January, for each person on each sheet starts on cell A4 and stretches all the way to cell Q34.

    each sheet has column F, in January F4-F34, in which a "Y' or "N" is input, demming yes or no for commission payout.

    information that i want exported in within cells A4:Q34, but i dont need all of the cells. I only need A4:C34 - F4:F34 - I4-Q34. Once the code is in place for one, it should be easliy modified for all cells and sheets.

    With in the code i want to be able to create unique sheet names, so that when the export is done, "John Smith January 2010" (as an example) is created outside of the current workbook and only containing the cell ranges, and not the entire sheet.

    this whole process is to help avoid having to rewrite an entire workbook, that is working perfectly just to get a snip of information in a different way.

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    Ok, it is easy to change the code to add a new blank sheet instead of copying the whole sheet:

    Please Login or Register  to view this content.
    However, I think we need to modify that sinse you will want to run it for each employee in that particular workbook.
    Are all the sheet in the workbook one of the employee sheets, or do you have any summary or other info sheets?
    On what cell is the name of the employee for each sheet? On what cell is the month and year for that set of data?

  9. #9
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    All of the sheets are in the same workbook and all the employee names are in the same cell on each sheet (cell B2), where as cell A2 has the word Name: in it.
    Name: John Smith

    What i was thinking is that if the code has to be repoduced 12 times per employee that is fine, once for each month. Then all i have to do is set a call function to a button, click it and export the data to a new blank sheet, with just the specific cell data being transfered. To have that occur out side of the active workbook would be even better.

  10. #10
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    just tried the new code. it creates the blank page really well, but didnt transfer the cells....

  11. #11
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    the following attachment is my workbook cut way down, with the code and button in place. when you click the [export] button you will see that it creates a new blank sheet in the same workbook and none of the data transfers.
    Attached Files Attached Files

  12. #12
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Exporting

    try this:

    Please Login or Register  to view this content.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  13. #13
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    that works for what exactly? The thing i am trying to accomplish would take data from a specific cell range put it into a new sheet seperate from the current workbook.

    Currently the code i am trying to get to work is either creating a blank new sheet or copying the active sheet to another sheet with a new name. Both are great attempts but niether are hitting th mark yet.

    I know how to transfer data from a single cell using a button, I am just hoping to get a specific range instead and into a new sheet outside of the active workbook.


    I see what it does now...thanks. But I want to be able to run it off a button and only for specific cell ranges. That copies the entire page outside of the workbook...which is nice.
    Last edited by jabryantiii; 01-06-2010 at 08:24 PM.

  14. #14
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Exporting

    try this:

    select a range in your workbook and it will copy that range to another workbook..

    is this it?

    Please Login or Register  to view this content.

  15. #15
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    The reason my code was creating a blank sheet was because in your sample workbook, you have capital Y and N in column F. Your instructions earlier said uncapitalized y and n. If you change the "y" to "Y" in the code, it will tranfer the data.

  16. #16
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    I see what you mean. the capital Y vs lowercase y, made all the difference. Thank you very much for pointing that out...I was not paying attention to that at all. I have a code set up that uses "y" in it and it never cared about case sensitivity before or at least i didnt notice it being case sensitive before.

    now i need to figure out how to get that now-not-blank sheet to create outside of the workbook.

  17. #17
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    ok as wierd as this is I have combined the two codes to make a button that calls both subs. It creates the new sheet inside of the current workbook with the information i am looking for based on the "y" and "n" in column F, then it copies that page, err creates that page outside of the workbook. It works great, now i just need a way to do that without creating a copy inside the active workbook.

  18. #18
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    Simple, just delete the page inside the workbook after you have copied it out of the workbook.

    Please Login or Register  to view this content.
    To turn the warning off, use:

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    well that didnt work the way i was hoping.

    so now i am back to square 4, still need a way to create the data outside of the workbook.

    Dave,
    the code you came up with works great, thank you. I thought my crazy idea of combining the other code with yours to create the data outside of the workbook would work and it did, until i add the delete idea. Any ideas on how to step the code so that it creates the new sheet outside of the workbook instead of inside the active workbook?

  20. #20
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    What specifically was the probelm with deleting the copy made inside the workbook?

  21. #21
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    it is deleting the copy inside the new workbook...or trying to at least.

  22. #22
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    so before you run the delete code, go back to the original workbook:

    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    ok...I need a cleaner way for this to work.
    I have an idea but i am not sure how to implement it.
    this code creates the sheet in it own workbook but not the range i want or with the delimiter based on the "y" vs "n". (i have tried the active cell highlighting and still end up with a reprduction of the entire page)

    Please Login or Register  to view this content.
    this code creates the data i want in the same workbook and the range i am looking for based on the "y" vs "n"

    Please Login or Register  to view this content.
    So some how i need to combine the above code(s) into one to not only grab just the data i want based on the "y" vs "n" but i also need to to be created outside of the original workbook.

    is it possible to set the created data to a specific cell on the new page, so that when i code the button to Feb, Mar, Apr, Jun....that they are all displayed on the top of the workbook?
    Last edited by jabryantiii; 01-08-2010 at 02:10 PM.

  24. #24
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Exporting

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    is there any way to do the exporting one line at a time and have it export to a specific sheet for formatting purposes, instead of cutting and pasting?

    the original code i posted has the ability to post one active cell at a time, instead i would like to export one line at a time based on the F4 "y" vs "n". I would also like to know if it is possible to verify that an exported row, is not double exported to the same sheet.

    what they would like is a January, February, etc sheet in the same workbook that just has the data exported when needed and only the "y" not the "n". so I figure it would be easier to export one line at a time and ensure that the data is not double exported. Hope that makes sense?!?
    as an example i would just like to export (A4:C4, F4,I4:Q4) to a sheet named January, and have it fall into corresponding cells without the spaces in between them, so (A4:M4).

  26. #26
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    To have this happen in realtime, the macro can watch column F for "y" entries being entered, and the macro can instantly copy the item to the appropriate sheets.

    This macro will create the January/February/etc sheets if they do not already exist, so you don't have to worry about that either.

    Lastly, the macro will check to make sure the item it is about to transfer has not already been transferred. It does this by checking the value in column B, the Account/Job Name field. If it is found, a message will pop to indicate so.

    1) Right-click on the sheet-tab John Smith and select VIEW CODE
    2) Remove the code in there currently
    3) Paste in this new sheet event macro
    Please Login or Register  to view this content.
    6) Close the editor and save your sheet
    7) fill in some rows and add "y" or "Y" to column F, they will transfer on their own. You will hear a "beep" letting you know it happened.
    8) You can delete the button

    NOTE: This macro will also work regardless of the capitalization of the y/Y, both are fine.
    Attached Files Attached Files
    Last edited by JBeaucaire; 01-15-2010 at 03:30 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  27. #27
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    so for each sales person a new sheet will be created? Is there a way to combine sales people on the same January sheet ie to a specific formatted area as to avoid seperate January sheets?

  28. #28
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    I see what had happened after I asked my previous I, I had added/copied the John Smith sheet and renamed it and then tried to transfer the data.

    I still would like to know about seperating the sales people into specific areas on the January sheet.

    so John Smith would be in the first 15 blocks as an example designated by a header with his name, and then the next sales person entered would be in say rows 20-35 under the same type of formating.

  29. #29
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    I wouldn't hard code it that way. You're just asking for headaches tweaking the code.

    Let's just add the name into the empty column A for each pasted row, then sort all the data. Doing this each time we add something will keep each person's items together without having to maintain separate "sections".

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 01-15-2010 at 07:55 PM.

  30. #30
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    So do I need to copy the code into each sheet? The reason I ask is because i created a test workbook created three sheets with in it, copied the code into each sheet and everytime i enter data in to any cell on the sheet(s) i get a complier error. F4 is blank at this point and still the compiler error shows up. Not sure why this is occuring.....

  31. #31
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    Post up your workbook with the macro already installed.

    BTW, if this is supposed to occur in every worksheet, we can restructure this into a single workbook-event macro in ThisWorkbook so you won't have to maintain a bunch of copies of the same macro.

  32. #32
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    tried posting...keep running into a database error from the site, as soon as i can i will post.

  33. #33
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    Try zipping the file first.

  34. #34
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    tried to post again...but the site is still giving me a database error

  35. #35
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    Try zipping the file first. There's a 1mb max on file sizes, I think.

  36. #36
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    wierd...the file unzipped is only 855KB
    Attached Files Attached Files

  37. #37
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    i know i am asking a dumbkid question, but is there a way to code this to a button? the reason for this is because in order for the data to transfer the F4 with the "y" has to be the last field input in order to export the data. Retraining an old habit out of someone is combersome, because the person filing the sheet out knows ahead of time on wether the "y" or "n" goes in place and is attempting to input that field before the rest of the data. therefore it is not transfering all the data, just the data prior to the "y". With a button or or if you have a better solition all the data on the row will be transfered based on the "y" reguardless of the order the data is input....

  38. #38
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    1) Don't merge cells. There's no reason to merge columns S:Z to make wide cells when simply widening column S does the same thing. Merging cells on sheets you want to run macros on just makes more unnecesssary work.

    I unmerged them and widened column S.

    2) The unused cells in column A have to be empty for this to work properly. Right now, there is a hidden character in cell A5 that is messing it up. I'm sure it was accidental, but be aware.

    3) Here's a regular macro version, goes in a standard module:
    Please Login or Register  to view this content.
    4) Open the FORMS toolbar and add a form button, assign the macro "Transfer" to it. Use the button to initiate the transfers.
    Attached Files Attached Files
    Last edited by JBeaucaire; 01-19-2010 at 07:08 PM.

  39. #39
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    that works to perfection...I thank you very much for all of the amazing help.

  40. #40
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)

  41. #41
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Exporting

    is it ok to say i spoke to soon?
    I was testing the macro in a larger scale and noticed something minor. When a new month is exported to March for example, the header in the formatting for the month on the actual sheet dispalys January. To double check this I checked June, August and December, all with the same results.

  42. #42
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Exporting

    Add this one line:
    Please Login or Register  to view this content.

+ 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