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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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?

Customer / Project</SPAN>2012 Actual</SPAN>Org Chart</SPAN>Due Date</SPAN>Potential</SPAN>Grade</SPAN>Stage</SPAN>Forecast</SPAN>% Chance</SPAN>MH Forcast</SPAN>Notes</SPAN>
Project2</SPAN>Bitmap </SPAN>Bitmap </SPAN>Bitmap </SPAN>Bitmap </SPAN>-</SPAN>-</SPAN>-</SPAN>£15,000</SPAN>3</SPAN>F</SPAN>£15,000</SPAN>l</SPAN>50%</SPAN>£15,000</SPAN>Bla Bla Bla</SPAN>
Project3</SPAN>Bitmap </SPAN>Bitmap </SPAN>Bitmap </SPAN>Bitmap </SPAN>-</SPAN>-</SPAN>-</SPAN>£15,000</SPAN>3</SPAN>F</SPAN>£15,000</SPAN>l</SPAN>100%</SPAN>£15,000</SPAN>Bla Bla Bla</SPAN>

<TBODY>
</TBODY>
 
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.

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

<TBODY>
</TBODY>


(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,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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