Forum Discussion
neilbicknell
Apr 29, 2019Copper Contributor
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 r...
Wyn Hopkins
Apr 30, 2019MVP
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
neilbicknell
Apr 30, 2019Copper 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 | ||||
- Wyn HopkinsApr 30, 2019MVPAh 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.- neilbicknellApr 30, 2019Copper Contributor
Wyn Hopkins yes i understood this. The code did not work:(
- Wyn HopkinsApr 30, 2019MVP
- neilbicknellApr 30, 2019Copper Contributor
Wyn Hopkins yes I understood that much. I enter this code on sheet 1 and it does not do anything, having changed move to "New"