Sub AddAccounts()
'
'
Dim HeaderRow As Integer
Dim DataStartRow As Integer
Dim CopyFromCol As Integer
Dim CopyToCol As Integer
Dim LastRow As Integer
Dim MySheet1 As String
Dim MySheet2 As String
Dim MySheet3 As String
Dim MyReportSheet As String
'
'Define the Rows, Cols and Worksheet names for your file
'Be sure to include the Worksheet names in "'s
'
HeaderRow = 6
DataStartRow = HeaderRow + 1
CopyFromCol = 2
CopyToCol = 2
MySheet1 = "2016 Time Log"
MySheet2 = "2017 Time Log"
MySheet3 = "2018 Time Log"
MyReportSheet = "Test Sheet"
'
'The following code creates a temporary sheet on which to copy each list of Accounts,
'appending each list below the prior one. It then Sorts and does an Advanced Filter to hide
'all duplicate values, then copies the "shorened" list to where you want it.
'Once the copy is complete, it deletes the temporary sheet.
'
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "TempSheet"
Sheets(MySheet1).Select
Cells(HeaderRow, CopyFromCol).Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Copy
Sheets("TempSheet").Select
Range("A1").Select
ActiveSheet.Paste
Sheets(MySheet2).Select
Cells(DataStartRow, CopyFromCol).Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Copy
Sheets("TempSheet").Select
Range("A1").Select
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Cells(LastRow, 1).Offset(1, 0).Select
ActiveSheet.Paste
Sheets(MySheet3).Select
Cells(DataStartRow, CopyFromCol).Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Copy
Sheets("TempSheet").Select
Range("A1").Select
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Cells(LastRow, 1).Offset(1, 0).Select
ActiveSheet.Paste
Range("A1").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("TempSheet").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("TempSheet").AutoFilter.Sort.SortFields.Add Key:= _
Range(ActiveCell, ActiveCell.End(xlDown)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("TempSheet").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range(ActiveCell, ActiveCell.End(xlDown)).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets(MyReportSheet).Select
Cells(DataStartRow, CopyToCol).Select
ActiveSheet.Paste
Sheets("TempSheet").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete
End Sub