+ Reply to Thread
Results 1 to 15 of 15

Macro to Move Entire Row Based on Cell Contents

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Macro to Move Entire Row Based on Cell Contents

    Hi all,

    I have a report to calculate commissions for salespeople. I have raw data and then six sheets, one for each of six salespeople. I'd like to create a macro that will read column B, and based on which salesperson it is, move that entire row to that salesperson's sheet.

    For instance, if on the "data" sheet B2 says "Johnson, Ted", I would like row 2 to get moved to the "Johnson" sheet row 7
    Then if on the "data" sheet, B9 says "Johnson, Ted", I would like row 9 to get moved to the "Johnson" sheet row 8
    Similarly, if on the "data" sheet, B12 says "Martin, Julie", I would like row 12 to get moved to the "Martin" sheet row 7

    Any help is appreciated and let me know if I can provide more details.

    The spreadsheet is attached.

    Jordan
    Attached Files Attached Files
    Last edited by alpha608; 12-27-2012 at 01:59 PM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    Will these sheets already be created or will code need to create them also?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    This will work if they will and if there is a , in column B

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Macro to Move Entire Row Based on Cell Contents

    Do you need the row to clear in your data sheet?

    I mean once transfered to the desired sheet to clear the selected row.
    Last edited by Excelnoub; 12-27-2012 at 01:21 PM.

  5. #5
    Registered User
    Join Date
    12-27-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to Move Entire Row Based on Cell Contents

    The sheets for each salesperson are already created. It would be helpful if the row cleared in the data sheet.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    Ok try this

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-27-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to Move Entire Row Based on Cell Contents

    Hi Mike,

    I tried that revised version and its very close. First, on my real "data" sheet, I have 11 columns, not just 6 (I had to hide details for confidentiality). Second, on my real spreadsheet when the data moved to the specific salesperson's sheet it input below all of the calculations I already have on that salesperson's sheet. How would one go about scripting it so that when it moved the data it started on row 7 of the salesperson's sheet?

    Thanks,

    Jordan

  8. #8
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Macro to Move Entire Row Based on Cell Contents

    Hey Jordan I was just playing with it let me know what you thinkTestCommissionsReport(1).xlsm

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    Maybe this

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Macro to Move Entire Row Based on Cell Contents

    If you like it let me know I will tweek it to your need.

    IE: I have 11 columns, not just 6

    I added a control sheet for names and selection. I find it is easier this way when you have repeated data and also for transfer.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to Move Entire Row Based on Cell Contents

    @ mike7952,

    There is nothing wrong with that, except maybe adding "Option Explicit"
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  12. #12
    Registered User
    Join Date
    12-27-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to Move Entire Row Based on Cell Contents

    Hi Mike,

    I tried the revised version and it does what I am looking for. Thanks! One question: if our company hires new salespeople and I add new tabs for them, will this same macro work?

    Thanks,

    Jordan

  13. #13
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    Option Explicit

    Thanks Winon... Yea Somethimes i leave that to the OP.

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Macro to Move Entire Row Based on Cell Contents

    @alpha608,

    Yes it will work... As long as column b has the same format as your example workbook. "Johnson, Ted" with the comma.

  15. #15
    Registered User
    Join Date
    12-27-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Macro to Move Entire Row Based on Cell Contents

    Awesome. Thanks so much!

+ 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