Macros need whole line moved to new worksheet automatically

aboyal

New Member
Joined
Sep 28, 2011
Messages
6
I want to create a macro that when date is inserted into certain cell, have the whole line moved to a new worksheet, and re move from original sheet.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
attempted to create the formula, but insufficient excel knowledge,<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
needs whole line moved to new worksheet if column "i" contains<o:p></o:p>
<o:p> </o:p>
-------------------------<o:p></o:p>
needs a macro that will<o:p></o:p>
1. check the completed date cell for data<o:p></o:p>
2. IF the data is present, then COPY the data in the row from one sheet to another<o:p></o:p>
3. THEN delete the data from the original sheet<o:p></o:p>
4. LOOP through and go to the next cell to check<o:p></o:p>
5. Variables would have to be used<o:p></o:p>
<o:p> </o:p>
<o:p>Any guidence would be super appriciated </o:p>
<o:p>Thank you in advance! :ROFLMAO:</o:p>
 
OK, I assumed that you want it happen "on the fly", as dates are being manually typed into column E.
I also assumed that you want the blank row to be removed so that all other rows below move up one.
And your destination sheet ("Completed jobs") starts pasting data in the first blank row in column A and keeps moving down.

So here is the code that I came up with. Right click on the sheet tab name of the sheet you are typing the dates into, select "View Code", and paste the following code in the resulting VB Editor window:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
'   Check to see if a date has been added to column E
    If Target.Column = 5 And IsDate(Target.Value) And Target.Count = 1 Then
        Application.EnableEvents = False
        Call MyMove(Target.Row)
        Application.EnableEvents = True
    End If
    
End Sub
 
Private Sub MyMove(myRow As Long)
 
    Dim myOrigSheet As Worksheet
    Dim myDestSheet As Worksheet
    Dim myLastRow As Long
    Dim i As Long
    
'   Set sheets
    Set myOrigSheet = ActiveSheet
    Set myDestSheet = Sheets("Completed jobs")
    
'   Find last row on destination sheet
    If Len(myDestSheet.Cells(1, "A")) = 0 Then
        myLastRow = 0
    Else
        myLastRow = myDestSheet.Cells(Rows.Count, "A").End(xlUp).Row
    End If
    
'   Copy column A-H of row to new sheet
    For i = 1 To 8
        myDestSheet.Cells(myLastRow + 1, i) = myOrigSheet.Cells(myRow, i)
    Next i
    
'   Delete original row
    myOrigSheet.Rows(myRow).EntireRow.Delete
 
End Sub
Then as long as you have macros enabled, this code should run automatically and do what you want.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
(immediately upon entering data in this column)
YES column E

When the rows of data is removed from your original sheet, do you want the blank row deleted so that all other rows move up one?
YES pls

When the data is pasted into your "Completed jobs" sheet, do you want to start in row 1, and then put each succeeding row after that?
YES preferably after all content that is allready there if not as long as it goes to that list that would be great.

1 more thing that might need to be added
the work book has tabs at the bottom so 5 or 6 different lists would it be possible to move the row from one list to the exact row into the completed work book list if that makes sence? or do i just use the formula on each sheet?
 
Upvote 0
1 more thing that might need to be added
the work book has tabs at the bottom so 5 or 6 different lists would it be possible to move the row from one list to the exact row into the completed work book list if that makes sence? or do i just use the formula on each sheet?
Not sure I understand. Maybe an example would clarify it.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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