How To Move Entire Row To Various Sheet Based On Cell Value In Excel?

suicidalporcupine

Board Regular
Joined
Apr 1, 2015
Messages
90
Hello everyone,

all the tutorials I've search has the same result. Most tutorials shows you how to copy the Row from Sheet 1 to Sheet 2 only. Maybe I am not searching it properly? What I need is to COPY Row from Sheet 1 to Sheet 2 OR Sheet 3 OR Sheet 4 depending on the value on Column "M" Can someone please direct me to that site or show me the vba code on how to make it work? So example, if value = Daniel, then I want it to copy that row to "Daniel" Sheet. but if the value is "Brian" then it will copy that row to "Brian" sheet.

Thanks a bunch
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Yes, the actual list starts at A2.

Trying to read and understand the codes.

Will this work if I have almost a thousand rows. Because I am dealing with cases, and I want to know which lawyer is dealing with which cases.

what if there's already a "named" sheet. will it recreate a new sheet or copy and paste onto the existing sheet?

in which part do I enter the names of the sheets for my project?
 
Upvote 0
Did this in the car....so is untested !!

Code:
Sub MM1()
Dim lr As Long, r As Long, ls As Long
lr = Cells(Rows.Count, "M").End(xlUp).Row
For r = 2 To lr
    ls = Sheets(Range("M" & r).Value).Cells(Rows.Count, "A").End(xlUp).Row
    Rows(r).Copy Sheets(Range("M" & r).Value).Range("A" & ls + 1)
    ls = ls + 1
Next r
End Sub
 
Upvote 0
also, instead of Column B, can I change to Column M? and if so, what/where can I change that within the code?

code is flexible and should not need any changes. when the inputbox appears, just click on the column heading you want to filter - data will be copied to existing worksheet(s) or a sheet will be created if it does not exist.

Dave
 
Upvote 0
Did this in the car....so is untested !!

Code:
Sub MM1()
Dim lr As Long, r As Long, ls As Long
lr = Cells(Rows.Count, "M").End(xlUp).Row
For r = 2 To lr
    ls = Sheets(Range("M" & r).Value).Cells(Rows.Count, "A").End(xlUp).Row
    Rows(r).Copy Sheets(Range("M" & r).Value).Range("A" & ls + 1)
    ls = ls + 1
Next r
End Sub

I love it! Car Coding is beyond awesome! And yet I hope I'm not on the road with you :P
 
Upvote 0
Ummmm....I wasn't in the drivers seat...:beerchug:
 
Upvote 0
Thank you very much btw. this helps a lot. and if I want to any kind of code in the future, where do I exactly can place them? before the End Sub?
 
Upvote 0
I don't exactly follow you.....but you can put more subs in the module, so they work seperately
OR
you can insert code within the existing sub.
If you have further issues with code.....simply post back here !!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top