Move Row into new sheet based on cell value

cheezy

New Member
Joined
Dec 5, 2012
Messages
2
Hi Guys,

New here.

I have been searching the web and these forums and cannot find a specific solution.

I need write a VBA code that will move an entire row into a new sheet if the value of the last cell says "YES"
If the value is blank then Id like it to stay in the current sheet.
I would also like it if the cell wont allow any other value other than Yes to be typed.

I found this code here:

http://www.mrexcel.com/forum/excel-questions/397784-copy-move-delete-row-based-cell-value.html

THE VERY FIRST CODE REPLIED IN THAT THREAD.



I just cannot seem to get it to work. Simply copying and pasting that into the module doesn't work. I am not very good at VBA and just started taking a course on VBA.
Id like to jump into this problem asap as I need it for work.





Basically:

Columns A:E will have values. In Column E I would like to type in Yes if completed.
I would like the Macro to run through all of Column E and if the cell value is "YES" then I want it to cut the entire row and paste into a new sheet.
In the new sheet I would like it to be pasted into the next available row.

Also can I create this with a ActiveX control button? I would like to have a button that I can click at the end of my work which will run the Macro in sheet 1.

Thanks a lot guys an help is appreciated!
 
Last edited:
There is;

BNE Receivals
BNE Trimming
BNE Clean Room
BNE Packing
BNE Daily Fresh - Assembly
BNE Daily Fresh - Prep
BNE Despatch
BNE Hygiene

..and I wanted each to show on a separate tab.

Thanks for your help Michael!
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Pretty rough, but this assumes the following:
1. the sheet names to be created are on a sheet called "Name List" in column "A"
2. The master list starts at row 2
3. each time the code is run it refreshes ALL sheets by creating new ones

Code:
Sub MM1()
Dim x As Variant, wSh As Worksheet, r As Long, lastrow2 As Long, lastrow As Long
Dim ws As Worksheet
Set wSh = Worksheets("Name List")
Set ML = Worksheets("Master List")
wSh.Activate
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name <> "Master List" And ws.Name <> "Name List" Then
        Application.DisplayAlerts = False
        ws.Delete
        Application.DisplayAlerts = True
End If
Next ws
For Each x In wSh.Range("A1:A8")
Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = x.Value
Next x
ML.Activate
lastrow = ML.Cells(Rows.Count, "A").End(xlUp).Row
    For r = 2 To lastrow
    Select Case Range("A" & r).Value
         Case Is = "BNE Receivals"
         lastrow2 = Worksheets("BNE Receivals").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Receivals").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Trimming"
         lastrow2 = Worksheets("BNE Trimming").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Trimming").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Clean Room"
         lastrow2 = Worksheets("BNE Clean Room").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Clean Room").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Packing"
         lastrow2 = Worksheets("BNE Packing").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Packing").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Daily Fresh - Assembly"
         lastrow2 = Worksheets("BNE Daily Fresh - Assembly").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Daily Fresh - Assembly").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Daily Fresh - Prep"
         lastrow2 = Worksheets("BNE Daily Fresh - Prep").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Daily Fresh - Prep").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Despatch"
         lastrow2 = Worksheets("BNE Despatch").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Despatch").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
         Case Is = "BNE Hygiene"
         lastrow2 = Worksheets("BNE Hygiene").Cells(Rows.Count, "A").End(xlUp).Row
         Rows(r).Copy Worksheets("BNE Hygiene").Range("A" & lastrow2 + 1)
         lastrow2 = lastrow2 + 1
    End Select
    Next r
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Follow these steps


Copy the code that I posted
Open the workbook in which you want to add the code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste



To run the code:
On the Excel Ribbon, click the View tab
At the far right, click Macros
Select a macro in the list, and click the Run button
 
Upvote 0
What seems to be the problem ??
Did you read these initial instructions ?

Pretty rough, but this assumes the following:
1. the sheet names to be created are on a sheet called "Name List" in column "A"
2. The master list starts at row 2
3. each time the code is run it refreshes ALL sheets by creating new ones
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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