Forum Discussion
Jarvo
Mar 16, 2021Copper Contributor
VBA formula for archiving
Hi everyone, I've come across a very useful VBA formula for archiving data in my tables onto another sheet. The formula is as follows: Application.EnableEvents = False If Target.Column = 4 A...
- Mar 17, 2021
You placed the code for Selection Change Event on Current Sheet Module. Was it intentional or you did it by mistake?
Ideally you should place the code for Change Event so that when Status gets changed in Status column of the Table on Current Sheet, the data will be copied to the Saved or Archive Sheet accordingly based on the Status selected.
Please place the following code for Change Event on Current Sheet Module. In the attached I placed the code on Current Sheet Module for you to test it.
Private Sub Worksheet_Change(ByVal Target As Range) Dim tbl As ListObject Dim rng As Range Dim dws As Worksheet Dim dlr As Long Application.ScreenUpdating = False On Error GoTo Skip Set tbl = ActiveSheet.ListObjects("Table1") If Not Intersect(Target, tbl.DataBodyRange.Columns(4)) Is Nothing Then Application.EnableEvents = False Set rng = Intersect(ActiveSheet.Rows(Target.Row), Columns("A:G")) rng.Copy Select Case Target.Value Case "Save" Set dws = ThisWorkbook.Worksheets("Saved") Case "Closed" Set dws = ThisWorkbook.Worksheets("Archive") End Select dlr = dws.Cells(Rows.Count, "D").End(xlUp).Row + 1 dws.Range("A" & dlr).PasteSpecial xlPasteAll End If Skip: Application.CutCopyMode = 0 Application.EnableEvents = True Application.ScreenUpdating = True End Sub
Jarvo
Mar 17, 2021Copper Contributor
I did try that but it didn't work. Thanks for your help though!
NikolinoDE
Mar 17, 2021Platinum Contributor
Would it be possible to have the whole file (without sensitive data) or code?
So I could better understand what exactly you want to achieve. Correspondingly, if I am able to offer you a better proposal for a solution.
So I could better understand what exactly you want to achieve. Correspondingly, if I am able to offer you a better proposal for a solution.
- JarvoMar 17, 2021Copper ContributorGreat yeah I've just added a copy without the data. I am also having trouble with highlighting whole columns and rows and deleting them due to this formula. If you're able to work that out too you're a star. Thanks
- NikolinoDEMar 17, 2021Platinum ContributorIf you could briefly explain what exactly you want to accomplish, it would be great.
From where to where should the data go?
Column, row, cell.
Does it necessarily have to be in VBA, should one also make a proposed solution without vba?
Thank you for your patience and understanding