+ Reply to Thread
Results 1 to 20 of 20

Need help creating macro to move cells from same row to diff. Sheet based on value of cell

  1. #1
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Need help creating macro to move cells from same row to diff. Sheet based on value of cell

    hello all,

    i am fairly new to excel and i am struggling to find a solution to the following problem: i have this spreadsheet that keeps track of all of our machines in inventory and the machines are listed by an inventory number. the machines are sold by 7 different sales reps. what i need is to create a formula/macro/magic spell that will sort each sales rep. (column AJ) into a separate sheet and include the data from the row that the sales rep name appears on and the data found in the columns that i will specify below.

    columns: A:D, I, M:N, Q, AC:AF, AI:AK

    i also want it to update if i make any changes to the master spreadsheet.

    do i have to have sales rep sheets in the same workbook as the master sheet or can i put them together in their own workbook?

    i have attached a copy of my spreadsheet.

    thank you so much for your help in advance and i apologize if i have posted this question in the wrong section.
    Attached Files Attached Files
    Last edited by lmh79; 02-07-2013 at 01:39 PM. Reason: forgot to add columns i wanted included

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    You have two columns with Sales Rep, one is Buyer, the other is Seller. Which column do you want to use as a basis to create a new sheet for each rep?

  3. #3
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    column AJ
    please check my post, i updated it with the columns i would like copied
    thank you!

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Hello lmh79. I think the following code will work for you. There is only one little problem I can't seem to figure out. I think my brain is a little frazzled! You have to run the macro twice. The first time it creates the sheets and the second time it tranfers the rows. Try it out and see what you think. I'll keep working on the problem and maybe in the meantime, there is someone else in the forum who can figure out why you have to run the macro twice.

    Please Login or Register  to view this content.

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Try the attached
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    thank you both for your replies! yet again, i am new to this macro version of excel.. is there any way someone can tell me how to apply either of these helpful tips to my master spreadsheet? i am kind of intimidated by this new frontier..

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    What do you mean by master spreadsheet? My code creates tabs(sheets) for each sales person based on column AJ. As you can from the attached, the code has created tabs for each person. You can amend sheet 1, or master sheet, as many times as you wish and re-run the code, it will populate the tabs with new data, or if you add a new sales person, it will create a new tab with that persons data.

  8. #8
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    ok. so i just copy my spreadsheet into sheet one of the workbook you created and it will give me the data i need. my other question is: how do i alter the sales reps. sheets to only include these columns?
    A:D, I, M:N, Q, AC:AF, AI:AK

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Okay, instead of copying specific columns and makes the code messy and slow, I would rather copy the entire row and then delete the unwanted columns. Please check and this if I miss anything.

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

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Hello AB33. I believe that the following two macros will do what lmh79 wants but I was hoping you might be able to explain to me (just to add to my learning of VBA) why the two macros have to be run separately. When I try to combine them, the sheets are created but the data is not copied over to each sheet. When run separately, they work. Many thanks.

    Please Login or Register  to view this content.

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Okay, Mumps 1, give me few minutes to look at your code

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Mumps 1,
    I think the first of your code works, that it creates sheet names, but the second part does not copy the ranges. I just combined both codes by calling the second from the first one.

    Please Login or Register  to view this content.

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Thank you, AB33. I found the problem. After the last sheet was created, it remained, of course, as the active sheet. When the section of code that copies over the data runs, it applies to the active sheet instead of Sheet1. I added one line to make Sheet1 the active sheet and then copy the data and this worked.

    Please Login or Register  to view this content.

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Mumps 1,
    Great!
    You probably need to add to your code Application screen updating to speed up the code.
    You also need to include the heading for each sheet.

  15. #15
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    thank you both so much for your help! i copied and pasted my spreadsheet into the workbook that AB33 sent to me and it looks like all i need to do is format the sheets with the SR names.

    i have one more favor to ask: is there any way you can tweak the code you wrote to include column AI along with AJ-- so that if the sales rep name appears in either column, the data in that row will show up in that sales rep sheet.

    thank you!

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    I just want to clarify what you are asking. To use and example from your sheet .... in row 4, Mike appears in Column AI and Clay T appears in column AJ. Do you want row 4 to be copied to both Mike's and Clay's sheets?

  17. #17
    Registered User
    Join Date
    10-30-2012
    Location
    south carolina
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    yes, please.

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    Please Login or Register  to view this content.

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    lmh,
    I spent a couple of hours on this thread as you keep changing your request. Having read Mumps' reply, my last code does not duplicate names. For e,g in row 5 you have Mike in both columns, my code will create a single mike's sheet name. In other words, if the name appears in both columns, it will only copy one name, but if the name does not appear in column AJ, but in AI, it will create a new name as this name does not exist in both columns.

    Please try my code and clarifay what is missing

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

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    lmh,
    I spent a couple of hours on this thread as you keep changing your request. Having read Mumps' reply, my last code does not duplicate names. For e,g in row 5 you have Mike in both columns, my code will create a single mike's sheet name. In other words, if the name appears in both columns, it will only copy one name, but if the name does not appear in column AJ, but in AI, it will create a new name as this name does not exist in either column.

    Please try my code and clarifay what is missing

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Need help creating macro to move cells from same row to diff. Sheet based on value of

    @AB33 Thank you so much for your suggestions.

    @lmh. Please have a look at this attachment. See if it does what you wanted.
    Attached Files Attached Files

+ 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