VBA to archive data with Specific Value & Macro to email when a button is clicked.

samunders

New Member
Joined
May 26, 2020
Messages
27
Office Version
  1. 2019
Hello Guys,

Firstly thank you for any help that comes my way, I am slowly picking up tips from this message board but I haven't quiet got my head around VBA.

I am building (trying to build) a handover sheet for active things of note, and when they are completed based on a yes value move that "active" hand over to the Archive sheet.

The first one is a macro to send a generic an email to 4 email addresses when a new submission is made, this is to prompt people to check the worksheet when something new is added.

The second is to copy and paste 1 row to the archive sheet and then delete 3 rows from the the active sheet, with the archives auto sorted to with most recent.

I hope this and the screen shots help

Thank you so much for any help offered.
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    127 KB · Views: 10
  • Capture2.PNG
    Capture2.PNG
    147.6 KB · Views: 10
  • Capture3.PNG
    Capture3.PNG
    129.6 KB · Views: 9

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I have managed to do this but I get run time error when i insert copied cells on to the existing sheet, any suggestions?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 14 And UCase(Target) = "YES" Then
        Cells(Target.Row, Target.Column).EntireRow.Copy Destination:=Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 14 Then Exit Sub
    If Target = "YES" Then
        Target.EntireRow.Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "A").End(xlUp).Offset(1)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 14 Then Exit Sub
    If Target = "YES" Then
        Target.EntireRow.Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "A").End(xlUp).Offset(1)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
    End If
End Sub

That have stopped the error with the macro from the Create > Active Worksheet. however now I'm trying to hit yes in Colum 14, its not copying, pasting to the archive sheet, then deleting the target row
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column = 14 And UCase(Target) = "YES" Then
        Target.EntireRow.Copy Sheets("Archive").Cells(Sheets("Archive").Rows.Count, "A").End(xlUp).Offset(1)
        Application.EnableEvents = False
        Rows(Target.Row).Delete
        Application.EnableEvents = True
    End If
End Sub

This seems to have done the trick.


I now need to get the Cells D6 and onward in Colum D to auto sort with the newest at the top when the worksheet is open
 
Upvote 0
VBA Code:
Private Sub Workbook_Open()

    Sheet4.Range("D6:D99999").Sort key1:=Sheet2.Range("D6:N99999"), order1:=xlAscending, Header:=xlYes

End Sub

Would this work?
 
Upvote 0
Try:
VBA Code:
Private Sub Workbook_Open()
     Sheets(4).Cells(1, 4).Sort Key1:=Columns(4), Order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
End Sub
Make sure you place the macro in the code module for ThisWorkbook.
 
Upvote 0
Still not working this is the VBA for the macro I just want it to run when i open the work book

VBA Code:
Sub Sort_Archive()
'
' Sort_Archive Macro
'

'
    Range("D6:D17").Select
    ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Add Key:=Range("D6"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Archive").Sort
        .SetRange Range("D6:N99999")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 

Attachments

  • Untitled.png
    Untitled.png
    219.6 KB · Views: 0
Upvote 0
Could you upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,039
Members
449,063
Latest member
ak94

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