how to filter/move rows based on worksheet names?

blist

New Member
Joined
Mar 11, 2004
Messages
20
My spreadsheet has 10 worksheets named A-J. In worksheet A, my entire inventory is posted to a thousand+ rows, with all entries in Col 1 containing the same A thru J data. A-J names will not change.

What is the easiest way to move entire rows from worksheet A to worksheets B-J where Col 1 data = worksheetsheet name? Some Col 1 data on worksheet A already matches the sheetname A, and does not need to be moved.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
would there be a chance that the item on sheet A could already be on it's assignment sheet? So would you overwrite the line or just append the new line?
 
Last edited:
Upvote 0
does this work?

Code:
Sub SheetA_J()
Dim LR As Long
Dim Sht As String
Application.DisplayAlerts = False
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    Sht = Cells(i, 1)
    If Sht <> "A" Then
            Rows(i).Cut Destination:=Sheets(Sht).Range("A" & Rows.Count).End(xlUp) + 1
    End If
Next i
MsgBox "Done"
Application.DisplayAlerts = True
End Sub

note: this is untested
 
Last edited:
Upvote 0
Thanks for your reply!

When I run the code, it shows a Type mismatch error at this line:
Rows(i).Cut Destination:=Sheets(Sht).Range("A" & Rows.Count).End(xlUp) + 1
 
Upvote 0
ok so I tested and made this change

Code:
Rows(i).Cut Destination:=Sheets(Sht).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Range("A1")
 
Upvote 0
texaslynn, Thanks again. I made a minor adjustment on this line and now it works as i need.

Code:
            Rows(i).Cut Destination:=Sheets(Sht).Range("A" & Rows.Count).End(xlUp).Range("A2")
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

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