Using Dates to Move Completed Projects to Another Sheet

Hawksfand

New Member
Joined
May 18, 2015
Messages
3
Hi!
I've tried for a couple hours to figure this one out on my own and just can't seem to get the right combination going.

I need a macro that will look down a column of dates (and blank spaces for items that are not yet completed) and take out the ones that are older than a week and put them into another sheet with the exact same table specifications. The sheet names are "Display" and "Completed" and the row should be deleted after this move. The column is H and it starts in row 3. If a lot of notes could be added to explain what is going on in the code that would be great!

Let me know if you need more details, or if something doesn't make sense
Thanks!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
It is assumed that values in column H equate to a full date (eg. 5/18/2015) and are formatted as Date.
The designation of which sheet name applied to what was unclear, so you can replace the sheet index number in the set statements with the names where you see 'Edit sheet name'.
Code:
Sub moveCompl()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, i As Long
Set sh1 = Sheets(1) 'Ecit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells(Rows.Count, "H").End(xlUp).Row 'find last row with data in column H
    For i = lr To 3 Step -1 'Go from bottom up for row deletions on sh1
        If Date - sh1.Cells(i, "H").Value > 7 Then 'Check criteria
            sh2.Rows(3).Insert 'use inert method to keep in same order as sh1
            sh1.Rows(i).Copy
            sh2.Range("A3").PasteSpecial xlPasteAll 'use paste special to get formatting.
            sh1.Rows(i).Delete
        End If
    Next
End Sub

Be sure to enclose your sheet names in quotation marks inside the parentheses.
 
Last edited:
Upvote 0
It is assumed that values in column H equate to a full date (eg. 5/18/2015) and are formatted as Date.
The designation of which sheet name applied to what was unclear, so you can replace the sheet index number in the set statements with the names where you see 'Edit sheet name'.
Code:
Sub moveCompl()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, i As Long
Set sh1 = Sheets(1) 'Ecit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells(Rows.Count, "H").End(xlUp).Row 'find last row with data in column H
    For i = lr To 3 Step -1 'Go from bottom up for row deletions on sh1
        If Date - sh1.Cells(i, "H").Value > 7 Then 'Check criteria
            sh2.Rows(3).Insert 'use inert method to keep in same order as sh1
            sh1.Rows(i).Copy
            sh2.Range("A3").PasteSpecial xlPasteAll 'use paste special to get formatting.
            sh1.Rows(i).Delete
        End If
    Next
End Sub

Be sure to enclose your sheet names in quotation marks inside the parentheses.

So I tried it out and at the moment it isn't erroring, but it also isn't giving me any sort of result (nothing is being deleted or moved or anything). I've looked over the code to see if I could solve it but it's over my head


Code:
Sub moveCompl()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, i As Long
Set sh1 = Sheets("Display") 'Ecit sheet name
Set sh2 = Sheets("Completed") 'Edit sheet name
lr = sh1.Cells(Rows.Count, "H").End(xlUp).Row 'find last row with data in column H
    For i = lr To 3 Step -1 'Go from bottom up for row deletions on sh1
        If Date - sh1.Cells(i, "H").Value > 7 Then 'Check criteria
            sh2.Rows(3).Insert 'use inert method to keep in same order as sh1
            sh1.Rows(i).Copy
            sh2.Range("A3").PasteSpecial xlPasteAll 'use paste special to get formatting.
            sh1.Rows(i).Delete
        End If
    Next
End Sub
 
Upvote 0
The code should be copied to the standard code module 1. Try reversing your sheet names for sheets 1 and 2. My test set up used sheet 1 for the sheet to search column H and sheet 2 as the destination sheet for the copied data. The code ran without error and produced the desired results for me.
 
Upvote 0
Welcome to the Board!

If you keep all of your data on one sheet you can use Pivot Tables to summarize Complete/Open items.
 
Upvote 0
So it works and I'm just an idiot...I put in the 15th as the date completed and naturally it found nothing older than a week...
Thanks so much for your help!

@Smitty:
I would do that but we want to display the main sheet so we don't want to have other things on there cluttering it up.
Thanks though!
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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