Forum Discussion
Excel 2010 VBA to Move rows in a sheet based on the project Status
I have found so many different codes for this it's ridiculous. I don't think it should be very complicated. I want to move an entire row of data in sheet 1 based on the status of column "C" in that row, in sheet 1 , to sheet 2. I want the rows in sheet 2 to be a running list- IE not keep overwriting. Can someone please help me?
18 Replies
Hi neilbicknell
Apologies this code is a bit rough, I'm not a fan of hardcoding cell references and counters but hopefully this gives you an idea and you can tweak it to suit
Sub MoveToSheet2() Dim i As Integer Dim RowToRemove As Range For i = 1 To 1000 Sheet1.Range("C1").Offset(i, 0).Select If Selection.Value = "move" Then Set RowToRemove = Selection Sheet2.Range("A1").EntireRow.Insert Selection.EntireRow.Copy Sheet2.Range("A1") RowToRemove.EntireRow.Delete i = i - 1 End If Next i End Sub
- neilbicknellCopper Contributor
Wyn Hopkins thank you but that code didn't do anything.
I need rows 2, 4 and 5 to move to sheet 2 based on the Status of "new" being selected. This will be selected by a drop down box list of data. please help as I don't really know anything about coding
Date Name Status 10-Jan Bob New 10-Feb Sue Closed 12-Feb Jan New 13-Dec Frank New DATA New Closed Dead - Ah Ok, so in the code you need to change the word "move" to "New"
Also the i = 1 to 1000 means the code will run for 1,000 rows. Increase or decrease this number as required.
I would really warn against using VBA code if you are not very familiar with it as it can lead to unintended errors.