+ Reply to Thread
Results 1 to 9 of 9

VBA Loop multiple criteria to correct sheets

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Miami, USA
    MS-Off Ver
    Excel 2007
    Posts
    32

    VBA Loop multiple criteria to correct sheets

    Good morning everyone,

    I'm running into some problems looping through more then one criteria. I have added a attachment am an trying to look the correct data to the correct sheet.

    For example
    If cell B2 is equal to 1, then copy and paste row onto sheet2 and delete row
    If cell B2 is equal to 2, then copy and paste row onto sheet3 and delete row
    If cell B2 is equal to 3, then copy and paste row onto sheet4 and delete row

    Once the data in the row has been copy and pasted to the correct sheet, I would like to delete the row and continue until all the data has been looped.

    Any help would be appreciated.

    Thank you,

    Pinstripe

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: VBA Loop multiple criteria to correct sheets

    Perhaps like this?

    To test run macro "Move_Data"

    Alf

  3. #3
    Registered User
    Join Date
    07-11-2012
    Location
    Miami, USA
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: VBA Loop multiple criteria to correct sheets

    Thanks Alf that worked awesome. I tried using it against the data that I had and I ran into a few problems. Sorry, I realized I should have attached the actual data that I was working on instead of a general example. I have attached an updated copy of what I am doing. I am looking to copy each ID to the correct ID sheet along with all the data in the row. Do you think you can help?

    Sorry again Alf, but the code you did give my worked exactly like I asked in the first example.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Loop multiple criteria to correct sheets

    Please Login or Register  to view this content.
    Last edited by AB33; 01-06-2013 at 02:20 PM.

  5. #5
    Registered User
    Join Date
    07-11-2012
    Location
    Miami, USA
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: VBA Loop multiple criteria to correct sheets

    Thanks AB33 that worked perfect, genius. Is there a way to delete each row after it pastes to the correct sheet? If not, its okay. I appreciate both of your guys help!

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,794

    Re: VBA Loop multiple criteria to correct sheets

    No problem.

    Her comes an update with a modified macro so see if this fits the bill. As before run same macro.

    Alf

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Loop multiple criteria to correct sheets

    Plese see adjusted Code

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA Loop multiple criteria to correct sheets

    Pin,
    I assumed that you do not want to clear the heading on sheet 1, but if you also want to delete every cell on sheet 1,
    you can use this code,

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-11-2012
    Location
    Miami, USA
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: VBA Loop multiple criteria to correct sheets

    Work great guys. I tried both and they are flawless. Thanks again for everything.

+ 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