VBA code to automatically archive updated data only

irelanduser22

New Member
Joined
Mar 10, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Good morning,

I'm new to VBA and have experimented with a couple of codes but not quite got to what I want to achieve.

I have a progress tracker worksheet "Tracker" where multiple users will update on their respective tasks. Once complete, they will add the date of the progress update in Column T. Each time the date in Column T is amended, I want a copy of the data in that row only to be sent to a separate "Archive" sheet.

I've experimented with a Private Sub Worksheet_Change(ByVal Target As Range) code similar to the below with some success, but only by including a "Yes/No" update complete field in Column U. In addition, this code copies all rows each time any row is updated, rather than just the updated row.

Any help welcome,

Thanks.
 

Attachments

  • VBA Code.JPG
    VBA Code.JPG
    80.6 KB · Views: 32

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 20 Then Exit Sub
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    If IsDate(Target) Then
        Target.EntireRow.Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "A").End(xlUp).Offset(1)
        Target.EntireRow.Delete
    End If
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 20 Then Exit Sub
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    If IsDate(Target) Then
        Target.EntireRow.Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "A").End(xlUp).Offset(1)
        Target.EntireRow.Delete
    End If
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
That's perfect, exactly what I was after - just removed the Target.EntireRow.Delete line so the latest update is always visible in the main tracker. Thanks very much.

One follow up query (apologies - probably a simple one), I'd like to password protect the "Archive" sheet so only authorised users can delete or edit the information. However, I want the above code to run regardless - so data can be copied into the archive by anyone, but only deleted form the archive by authorised users (who have the password).

Normal password protect prevents the code from running.
 
Upvote 0
Change the password (in red) to suit your needs.
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 20 Then Exit Sub
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    If IsDate(Target) Then
        With Sheets("Archive")
            .Unprotect Password:="MyPassword"
            Target.EntireRow.Copy .Cells(.Rows.Count, "A").End(xlUp).Offset(1)
            .Protect Password:="MyPassword"
        End With
    End If
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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