+ Reply to Thread
Results 1 to 20 of 20

Macro is not copying to other sheet, just clearing contents of select case

  1. #1
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Macro is not copying to other sheet, just clearing contents of select case

    So, I have this loop that I was formerly helped out with on here. It needed slight modification for my purposes, but works like a charm and taught me a lot about the possibilities of the "Select Case" functionality (which is awesome, thank you all who contributed). So I'm trying to help someone in another department solve a similar problem. My data set is very specific every day, where his varies. So, I'm starting a loop that will loop through multiple columns and, as it comes across select case data, will transfer (through offset range from active cell) to an isolated sheet. I feel like I'm really close. When I run the loop for the first row, it grabs all of the range from the active cell and offset and clears it, but does not paste it onto the new sheet.

    I'm sure this is going to be a simple fix for the experienced, so I'm hoping the answer is glaring and not a cause of some weird formatting issue with the data set. Any help you can offer will be so greatly appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro is not copying to other sheet, just clearing contents of select case

    What is the range that you want to loop through? Cell M3 to what?

  3. #3
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    That's the thing. The data set always changes, that's why I programed the loop to do until it hits an empty cell. It is supposed to grab the row as defined by Range(ActiveCell.Offset(0, -12).Address & ":" & ActiveCell.Offset(0, 29).Address) and copy it to a separate sheet, then move down one row and, if it meets the criteria set by the select case function do the same, if not continue down the row until it finds another example of the case.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    perhaps
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    Well, I tried this one and all it did was provide me the first row of data that matched the criteria and added it to the other sheet as many times as the original list is long. Thanks for the help, though, any other thoughts. Why would the original macro posted not add the rows to the copy sheet as is? It seems to be finding the conditional cases and clearing them, just not copying them to the alternative sheet.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    my bad-stupid typo
    Please Login or Register  to view this content.
    oughta be
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    I tried this one too. It's close. It copies the first row to the intended import sheet, but then stops. It doesn't help that the first example in the data set was in the first row (thus was the row transferred to the copy sheet ("Import")), but the second was not and it looks like the loop just stopped there. Hmm.

    I still don't see what's wrong with the original equation, just, for some reason, the data isn't moving to the intended "import sheet." It finds the row, clears it, but never transfers to the copy sheet. Any thoughts on why the original would do part of the function correctly as far as identifying the case row, but does not want to move data to copy sheet? The line I'm directly referencing is below:

    Please Login or Register  to view this content.
    Why would the selected range not paste into the ".Copy Sheets("Import")"?
    Last edited by Rokn; 11-04-2013 at 08:08 PM. Reason: formatting of the wording

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    you have to make the change I made in my last post. that line will not work as it was originally-it will just copy the same data repeatedly, as you mentioned

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro is not copying to other sheet, just clearing contents of select case

    I tested your original code and it worked for me?

  10. #10
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    Ouch, that sucks to know,. I thought there may be an issue with the data set because the original macro, the very first that I submitted, works in an alternative fashion just fine on another spreadsheet with different case criteria. Hmm. Well, I guess there's not a whole lot left to do with this one.

  11. #11
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    John, I just retried my original macro with a made-up data set and yeah, it clears the rows of the select cases as are found, but does not copy the data, so, there's still something wrong with the original post and it appears to be specific to the .copy sheet function. When you ran the original macro, did it copy to the sheet that you named "import," because it's still not doing that on mine.

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    perhaps you can post a sample that doesn't work for you?

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro is not copying to other sheet, just clearing contents of select case

    Quote Originally Posted by Rokn View Post
    John, I just retried my original macro with a made-up data set and yeah, it clears the rows of the select cases as are found, but does not copy the data, so, there's still something wrong with the original post and it appears to be specific to the .copy sheet function. When you ran the original macro, did it copy to the sheet that you named "import," because it's still not doing that on mine.
    Yes it did?

  14. #14
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    I have attached a simple test book so you all can see what the macro is doing. I have it setup to move the select case data to the import tab using a click button found on sheet 3. It is still just clearing the rows where the select case is found, not moving the data. Any thoughts would be greatly obliged. Thanks.
    Attached Files Attached Files

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    This did work, but when I try to duplicate the code to run it in column "N" it's not doing the same loop.

    Please Login or Register  to view this content.
    There is no debug error, it just fails to return data if the select case appears in any of the cells in column "N." Any help on how to get it to run this same loop string from row M through AP?

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    you need to reset n first-add
    Please Login or Register  to view this content.
    before the loop you added

  18. #18
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    This worked. It's funny, I couldn't get the macro to clear the contents of the row that I was copying in the new macro. The original one cleared the contents, but never copied. So I ended up building the entire macro to move the data and then remove duplicates, rather than clearing the data before the searching the next column for the select case. I really appreciate everyone's help on this. It seems I learn a lot every time I work up a new macro, and with all of your help too. Thanks again for assisting. You've made one of my peers very

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro is not copying to other sheet, just clearing contents of select case

    your latest version has remove the .ClearContents lines for some reason ;-)

  20. #20
    Registered User
    Join Date
    07-14-2013
    Location
    Grand Rapids, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Macro is not copying to other sheet, just clearing contents of select case

    Yeah, I removed it because I wasn't able to get it to work properly. As most things go with macros, I figured a work-around with the "remove duplicates" function at the end of the macro. I successfully ran it against a raw data set I was provided and although it worked great, it returned every account in the raw data. Having talked to my co-worker about this, I'm thinking the raw data is already scrubbed by our analytics team before it's presented to him and he didn't know it. So, I learned a lot, but it looks like he may have just had me chasing my own tail.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Select Case within For loop not copying sheets to a new workbook
    By buttonmasher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2013, 02:30 PM
  2. Concatenating the contents of several cells in a select and then copying that string
    By HorsePop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2013, 05:36 AM
  3. VBA macro worksheet copying/clearing duplicate entries
    By RainbowLettering in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2013, 02:23 PM
  4. Help with clearing contents macro
    By Chadwick24 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-24-2009, 02:25 PM
  5. Macro Help for Deleting Blank Rows & Clearing Cell Contents
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2006, 01:25 AM

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