Sub Structure()
'
' Macro2 Macro
'
Dim tbl As ListObject
Dim rng As Range
Dim iRow As Integer, iCol As Integer
Dim oRng As Range
Sheets("Today").Select
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A2"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(18, 1), Array(29, 1), Array(36, 1), Array(53, 1), _
Array(67, 1), Array(78, 1), Array(92, 1), Array(95, 1), Array(101, 1), Array(113, 1), Array _
(119, 1)), TrailingMinusNumbers:=True
Set rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes)
tbl.Name = "tTable"
tbl.TableStyle = "TableStyleLight8"
Range("A4").Select
ActiveCell.FormulaR1C1 = "=WORKDAY(R[-2]C,-1)"
Range("A4").Select
Selection.NumberFormat = "m/d/yyyy"
ActiveSheet.ListObjects("tTable").Range.AutoFilter Field:=12, Criteria1:=Range("A4").Value
Columns("D:D").ColumnWidth = 20
Range("A1").Select
Range("tTable[[#Headers],[Column12]]").Select
ActiveCell.FormulaR1C1 = "Last Maintainence Date"
Range("tTable[[#Headers],[Column11]]").Select
ActiveCell.FormulaR1C1 = "OD"
Range("tTable[[#Headers],[Column10]]").Select
ActiveCell.FormulaR1C1 = "VCR"
Range("tTable[[#Headers],[Column9]]").Select
ActiveCell.FormulaR1C1 = "TAR"
Range("tTable[[#Headers],[Column7]]").Select
ActiveCell.FormulaR1C1 = "SOR"
Range("tTable[[#Headers],[Column6]]").Select
ActiveCell.FormulaR1C1 = "DCR"
Range("tTable[[#Headers],[Column4]]").Select
ActiveCell.FormulaR1C1 = "Name"
Range("tTable[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "INIT"
Range("tTable[[#Headers],[Column2]]").Select
ActiveCell.FormulaR1C1 = "ID"
Range("tTable[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Region"
Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Copy
Worksheets.Add(After:=Worksheets(Sheets.Count)).Name = "Data"
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1").Select
Set rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes)
tbl.Name = "dTable"
tbl.TableStyle = "TableStyleLight8"
Sheets("Yesterday").Select
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A2"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(18, 1), Array(29, 1), Array(36, 1), Array(53, 1), _
Array(67, 1), Array(78, 1), Array(92, 1), Array(95, 1), Array(101, 1), Array(113, 1), Array _
(119, 1)), TrailingMinusNumbers:=True
Set rng = Range(Range("A1"), Range("A1").SpecialCells(xlLastCell))
Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, rng, , xlYes)
tbl.Name = "yTable"
tbl.TableStyle = "TableStyleLight8"
Columns("D:D").ColumnWidth = 20
Range("A1").Select
Range("yTable[[#Headers],[Column12]]").Select
ActiveCell.FormulaR1C1 = "Last Maintainence Date"
Range("yTable[[#Headers],[Column11]]").Select
ActiveCell.FormulaR1C1 = "OD"
Range("yTable[[#Headers],[Column10]]").Select
ActiveCell.FormulaR1C1 = "VCR"
Range("yTable[[#Headers],[Column9]]").Select
ActiveCell.FormulaR1C1 = "TAR"
Range("yTable[[#Headers],[Column7]]").Select
ActiveCell.FormulaR1C1 = "SOR"
Range("yTable[[#Headers],[Column6]]").Select
ActiveCell.FormulaR1C1 = "DCR"
Range("yTable[[#Headers],[Column4]]").Select
ActiveCell.FormulaR1C1 = "Name"
Range("yTable[[#Headers],[Column3]]").Select
ActiveCell.FormulaR1C1 = "INIT"
Range("yTable[[#Headers],[Column2]]").Select
ActiveCell.FormulaR1C1 = "ID"
Range("yTable[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Region"
Range("A1").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "Status"
ActiveCell.Offset(1).Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(IF(MATCH(RC[-9],dTable[Name],0),""yes"",),""no"")"
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
If Application.CountIf(ActiveSheet.ListObjects("yTable").ListColumns("Status").DataBodyRange, "yes") Then
ActiveSheet.ListObjects("yTable").Range.AutoFilter Field:=13, Criteria1:= _
"yes"
Columns("M:M").Select
Selection.EntireColumn.Hidden = True
ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort.SortFields. _
Add Key:=Range("yTable[[#All],[Name]]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Yesterday").ListObjects("yTable").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Data").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveSheet.ListObjects("dtable").ListRows.Add AlwaysInsert:=True
Sheets("Yesterday").Select
Range("A1").Select
ActiveSheet.ListObjects("yTable").DataBodyRange.Select
Selection.Copy
Sheets("Data").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1).Select
ActiveSheet.Paste
Range("A1").Select
ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort.SortFields.Add _
Key:=Range("dTable[[#All],[Name]]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Data").ListObjects("dTable").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Else: Sheets("Data").Select
End If
Range("A1").Select
Set oRng = Range("D1")
iRow = oRng.Row
iCol = oRng.Column
Do
'
If Cells(iRow + 1, iCol) <> Cells(iRow, iCol) Then
Cells(iRow + 1, iCol).EntireRow.Insert Shift:=xlDown
iRow = iRow + 2
Else
iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, iCol).Text = ""
'
Range("A1").Select
Columns("D:D").ColumnWidth = 20
Rows("2:2").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Columns.EntireColumn.AutoFit
Range("A1").Select
sFName = Application.GetSaveAsFilename
If sFName <> "False" Then ActiveWorkbook.SaveAs sFName
End Sub