Option Explicit
Sub LookAtData()
Dim wsIn As Worksheet, wsOut As Worksheet
Dim rIn As Range, rOut As Range, rOut1 As Range
Dim aIn As Variant
Dim iOut As Long, iRowIn As Long, iColIn As Long
Dim n As Long
Dim v As Variant
Application.ScreenUpdating = False
'save input
Set wsIn = Worksheets("Blad 1")
Set rIn = wsIn.Cells(1, 1).CurrentRegion
'get rid of header row and 2 extra columns
Set rIn = rIn.Cells(2, 1).Resize(rIn.Rows.Count - 1, 5)
aIn = rIn.Value
'remove existing Output
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("Output").Delete
Application.DisplayAlerts = True
On Error GoTo 0
'add new Output
Worksheets.Add.Name = "Output"
Set wsOut = ActiveSheet
'move data
iOut = 1
wsOut.Cells(iOut, 1).Value = "Name"
wsOut.Cells(iOut, 2).Value = "Location"
wsOut.Cells(iOut, 3).Value = "Color"
wsOut.Cells(iOut, 4).Value = "Date"
iOut = iOut + 1
'go down Input
'skip headers
For iRowIn = LBound(aIn) + 1 To UBound(aIn)
For iColIn = 2 To 5
'name
wsOut.Cells(iOut, 1).Value = aIn(iRowIn, 1)
'color
n = InStr(aIn(iRowIn, iColIn), "#")
wsOut.Cells(iOut, 3).Value = Left(aIn(iRowIn, iColIn), n - 1)
'date
aIn(iRowIn, iColIn) = Right(aIn(iRowIn, iColIn), Len(aIn(iRowIn, iColIn)) - n)
v = Split(aIn(iRowIn, iColIn), " ")
wsOut.Cells(iOut, 4).Value = DateValue(v(0)) & " " & TimeValue(v(1))
'location
wsOut.Cells(iOut, 2).Value = v(2)
iOut = iOut + 1
Next iColIn
Next iRowIn
'sort name ascending, date descending
Set rOut = wsOut.Cells(1, 1).CurrentRegion
Set rOut1 = rOut.Cells(2, 1).Resize(rOut.Rows.Count - 1, rOut.Columns.Count)
With wsOut.Sort
.SortFields.Clear
.SortFields.Add Key:=rOut1.Columns(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SortFields.Add Key:=rOut1.Columns(4), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange rOut
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'only keep first name entry = newest data
With rOut
For iOut = 2 To .Rows.Count - 1
If .Cells(iOut, 1).Value = .Cells(iOut + 1, 1).Value Then .Cells(iOut, 4).Value = True
Next iOut
On Error Resume Next
rOut.Columns(4).SpecialCells(xlCellTypeConstants, xlLogical).EntireRow.Delete
On Error GoTo 0
rOut.EntireColumn.AutoFit
End With
Application.ScreenUpdating = True
MsgBox "Done"
End Sub