Automatically move entire rows from one Worksheet into another Worksheet in the same Workbook

joeyjay

New Member
Joined
Jan 3, 2012
Messages
2
I have a Task List Workbook (with 2 Worksheets)

Worksheet 1 will be just for Open Task Items. Worksheet 2 will be just for Closed Items.

Worksheet 1 will consist of rows of Open Items.

The last column for each row on Worksheet 1 will either be a checkbox (for task completed) or a cell that we type a "completed date" into.

Once the last column cell is checked as completed or the cell is populated with a complete date, is there a way to have that be the trigger for the entire row to transfer over (be cut) from Worksheet to Worksheet 2 of the same Workbook?

Again, Worksheet 1 will be just for Open Task Items and Worksheet 2 will be just for Closed Items.

Thank you for your help.
 
BigC,

How can I (you) modify the code in order the cut rows to be transferred in a different workbook (e.g. Book 2)?

The approach with the same workbook but different sheet is building me a massive archive which is slowing down the current work. If the rows could be transferred to a new workbook, we would still have the working workbook and other workbook that would be used as storage.

I tried something, but unfortunately couldn't it by myself :(

Thanks a lot for your help and advice!
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,

Can you help.

I am trying to do something simular but I only want to transfer the whole row only when a certain year is put in the due date cell and not just any date. Also will the VB transfer all the formulas?

[TABLE="width: 1667"]
<TBODY>[TR]
[TD]Customer / Project</SPAN>[/TD]
[TD][/TD]
[TD][/TD]
[TD]2012 Actual</SPAN>[/TD]
[TD]Org Chart</SPAN>[/TD]
[TD]Due Date</SPAN>[/TD]
[TD]Potential</SPAN>[/TD]
[TD]Grade</SPAN>[/TD]
[TD]Stage</SPAN>[/TD]
[TD]Forecast</SPAN>[/TD]
[TD][/TD]
[TD]% Chance</SPAN>[/TD]
[TD]MH Forcast</SPAN>[/TD]
[TD]Notes</SPAN>[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Project2</SPAN>[/TD]
[TD]Bitmap </SPAN>Bitmap </SPAN>[/TD]
[TD]Bitmap </SPAN>Bitmap </SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]F</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD]l</SPAN>[/TD]
[TD]50%</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD="colspan: 4"]Bla Bla Bla</SPAN>[/TD]
[/TR]
[TR]
[TD]Project3</SPAN>[/TD]
[TD]Bitmap </SPAN>Bitmap </SPAN>[/TD]
[TD]Bitmap </SPAN>Bitmap </SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]-</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]F</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD]l</SPAN>[/TD]
[TD]100%</SPAN>[/TD]
[TD]£15,000</SPAN>[/TD]
[TD="colspan: 4"]Bla Bla Bla</SPAN>[/TD]
[/TR]
</TBODY>[/TABLE]
 
Upvote 0
... but I only want to transfer the whole row only when a certain year is put in the due date cell and not just any date. Also will the VB transfer all the formulas?

Will the trigger 'year' be static or change from time to time? Either way, I would recommend that this value be entered into a separate cell somewhere in Sheet1, and be assigned a Defined Name (say 'ArchiveYear') so that it can be easily changed without amending the code.

The code which triggers the move is:
Code:
     If IsDate(Target) Then
so this just needs to be changed to fire when your condition is met. Assuming all other matters in your model are the same as the original, the procedure could then be something like this (note additional/amended lines):
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDest as Range
Dim rngYear as Range
Set rngDest = Sheet2.Range("rngDest")
Set rngYear = Sheet1.Range("ArchiveYear")

' Limit the trap area to range of cells in which dates are entered as defined above
If Not Intersect(Target, Sheet1.Range("rngTrigger")) Is Nothing Then
' Only trigger if the year of the value entered matches the nominated archive year entered in the Defined Name "ArchiveYear"
     If Year(Target) = rngYear Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
        Application.EnableEvents = False
        Target.EntireRow.Select
        Selection.Cut
        rngDest.Insert Shift:=xlDown
        Selection.Delete
' Reset EnableEvents
        Application.EnableEvents = True
    End If
End If
End Sub

If I recall correctly (it's been a while and I don't have a copy of the model with me at the moment) the formulae in the model for which the original code was created only referred to other cells in the same row, so cutting and pasting them to another location does not cause a problem. However, if there are formulae that refer to cells outside that same row then it's another ball game.

HTH
 
Upvote 0
Thanks BigC,

That code worked great.

However, another thought cross my mind that on some instances the date maybe brought back a year back to the orignal sheet 1 or 2. I've played around abit with the code and managed to send the cells forward to sheet 1 for 2014 and sheet 2 for 2015 projects but can't see how I can revert them back if the date was changed as the "rngTrigger" and "rngDest" has moved from its original location. I've tried to add "rngDest" 2 and 3 and "rngTrigger1" but no luck.

I'm not an expert with on VB so not familiar with the syntax. Can you help?

Regards

Chris
 
Upvote 0
Hi Chris
Sorry, I don't understand what you're trying to do. What do you mean by:
  • "the date maybe brought back a year back to the original sheet 1 or 2.", and
  • "send the cells forward to sheet 1 for 2014 and sheet 2 for 2015 projects but can't see how I can revert
    them back if the date..."?
Can you please elaborate. (Note that the original application was not developed with any intention to allow for rows to be shuffled back and forth between "live" and "archive" sheets - but that doesn't mean we can't modify the original code to do so.)
 
Upvote 0
Sorry I hadn't made it clear.

What I need to do is the following.

I have a list of projects that I will put into sheet 1 and they will have an Due Date, however some may not start until 2014 or 2015 so they will need to be moved forward to sheets 2013 and 2014. In the future some of the projects in 2014 or 2015 due dates maybe brought forward to an earlier year and therefore will need to be moved back into 2014 or 2013.

Example: Sheet 2013 - all 2014 project will move to Sheet 2014 but may need to be moved back to sheet 2013 if the project is brought forward etc.

[TABLE="width: 1303"]
<TBODY>[TR]
[TD][/TD]
[TD]Customer / Project</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Org Chart</SPAN></SPAN>
[/TD]
[TD]Due Date</SPAN>
[/TD]
[TD]Potential</SPAN>
[/TD]
[TD]Grade</SPAN>
[/TD]
[TD]Stage</SPAN></SPAN>
[/TD]
[TD]Forecast</SPAN>
[/TD]
[TD][/TD]
[TD]% Chance</SPAN>
[/TD]
[TD]MH Forcast</SPAN>
[/TD]
[TD="colspan: 4"]Notes</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]30 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]1 January 2014</SPAN>
[/TD]
[TD]£99,000</SPAN>
[/TD]
[TD]1</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£0</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]25%</SPAN>
[/TD]
[TD]£0</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]31 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]1 February 2013</SPAN>
[/TD]
[TD]£99,001</SPAN>
[/TD]
[TD]2</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£0</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]25%</SPAN>
[/TD]
[TD]£0</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]32 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]1 February 2014</SPAN>
[/TD]
[TD]£99,002</SPAN>
[/TD]
[TD]3</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,002</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]25%</SPAN>
[/TD]
[TD]£0</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]33 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]12 April 2013</SPAN>
[/TD]
[TD]£99,003</SPAN>
[/TD]
[TD]4</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,003</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]75%</SPAN>
[/TD]
[TD]£99,003</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]34 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]12 July 2013</SPAN>
[/TD]
[TD]£99,004</SPAN>
[/TD]
[TD]5</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,004</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,004</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]35 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]23 June 2015</SPAN>
[/TD]
[TD]£99,005</SPAN>
[/TD]
[TD]6</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,005</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,005</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]36 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]1 January 2013</SPAN>
[/TD]
[TD]£99,006</SPAN>
[/TD]
[TD]7</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,006</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]100%</SPAN>
[/TD]
[TD]£99,006</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]37 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]1 February 2014</SPAN>
[/TD]
[TD]£99,007</SPAN>
[/TD]
[TD]8</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,007</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,007</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]38 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,008</SPAN>
[/TD]
[TD]9</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,008</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,008</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]39 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,009</SPAN>
[/TD]
[TD]10</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,009</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,009</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]40 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,010</SPAN>
[/TD]
[TD]11</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,010</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,010</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]41 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,011</SPAN>
[/TD]
[TD]12</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,011</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]50%</SPAN>
[/TD]
[TD]£99,011</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]42 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,012</SPAN>
[/TD]
[TD]13</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,012</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]100%</SPAN>
[/TD]
[TD]£99,012</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]43 Old Bailey (Skanska)</SPAN>
[/TD]
[TD][/TD]
[TD][/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]-</SPAN>
[/TD]
[TD]£99,013</SPAN>
[/TD]
[TD]14</SPAN>
[/TD]
[TD]C</SPAN>
[/TD]
[TD]£99,013</SPAN>
[/TD]
[TD]l</SPAN>
[/TD]
[TD]100%</SPAN>
[/TD]
[TD]£99,013</SPAN>
[/TD]
[TD="colspan: 4"]Blaa Blaa</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]


(TAB 2013) (TAB 2014) (TAB 2015)


Thanks,

Chris:)
 
Last edited:
Upvote 0
Hi Chris

If I understand you correctly, rather than rows being permanently removed from the single 'live' project sheet to a single 'archived projects' sheet for which the original application was developed, you want a set of live sheets (one per year - being the year in which project is due), with projects being moved between sheets as and when necessary according to a change in the year of the due date.

Questions:
  1. Is my understanding, as above, correct?
  2. What will be the trigger for a move - a change in the year of the project's due date , or something else?
  3. Do completed projects stay on their respective year sheet of are they to be moved to an archive sheet?


If your desired outcome is as I've outlined above, this should not be too difficult to achieve. Basically, each sheet would have identical code which would assess whether there is a change in year for any project on that sheet, and if so, move that row to the relevant sheet. (You may need to use Data Validation on the Due Date field of each sheet to ensure that the only dates accepted are those for which there is a year sheet in the workbook.)
 
Upvote 0
Hi,

I can confirm that the answer to your questions 1&2 is yes and again for Q3 I would like to archive projects if the projects trigger is Lost or Complete.


PS What the weather like over there?



Regards


Chris.
 
Upvote 0
Hi Chris

The weather in Perth is good (depending on what one wishes to do of course!) - though we're still experiencing generally dry conditions.

Re archiving projects if the projects trigger is Lost or Complete: What field in your table contains this trigger?

It will be difficult to write the code and provide instructions to modify the workbook to suit, so I'll send you a Private Message from within this site with my email address so you send me a copy of your file. I think I have the workbook I developed for the original post at home so can copy the code from there and modify it to suit.
 
Upvote 0
I have the same application as zoraxe, but I can't get the macro to work. I am a novice user and I am probably doing something incorrect. Below is what I have, Sheet1 is my active list and sheet2 is my archive. I am trying to move an entire row when column P is changed to "closed". Do I have to Define a name "closed"? on both sheet1 and shee2? I can't get the macro to run and when I step through it I have a bug on the row:
If Not Intersect(Target, Sheet1.Range("Closed")) Is Nothing Then

Macro:
Sub Worksheet_Change()
Dim rngDest As Range
Dim rngYear As Range
Set rngDest = Sheet2.Range("Closed")
' Limit the trap area to range of cells in which completed dates are entered as defined above
If Not Intersect(Target, Sheet1.Range("Closed")) Is Nothing Then
' Only trigger if the value entred is a date or is recognizable as a valid date
If UCase(Target) = "closed" Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
Application.EnableEvents = False
Target.EntireRow.Select
Selection.Cut
rngDest.Insert Shift:=xlDown
Selection.Delete
' Reset EnableEvents
Application.EnableEvents = True
End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,872
Messages
6,181,501
Members
453,047
Latest member
charlie_odd

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