Sub OpsReport()
'
' Attempt2Ops Macro
'
'
Sheets("Old").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Adding First, creating unique ID
Dim tst As Integer
Dim OrderNum As String
Dim UniqueId As Integer
' Find Order Number
tst = 2
Do While Cells(1, tst).Value <> "Order #"
tst = tst + 1
OrderNum = tst
Loop
' Find first blank column to create a unique Id
tst = 2
Do While Cells(1, tst).Value <> ""
tst = tst + 1
UniqueId = tst
Loop
' Print values
Cells(1, UniqueId).Value = "UniqueID"
f = 2
Do While Cells(f, 2).Value <> ""
Cells(f, 1).Value = "First"
Cells(f, UniqueId).Value = "=R[0]C" & OrderNum & "&R[0]C" & (OrderNum + 1)
f = f + 1
Loop
Sheets("New").Select
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
' Loop until blank row found
' Find Order Number
tst = 2
Do While Cells(1, tst).Value <> "Order #"
tst = tst + 1
OrderNum = tst
Loop
' Print values
Cells(1, UniqueId).Value = "UniqueID"
s = 2
Do While Cells(s, 2).Value <> ""
Cells(s, 1).Value = "Second"
Cells(s, UniqueId).Value = "=R[0]C" & OrderNum & "&R[0]C" & (OrderNum + 1)
s = s + 1
Loop
' copy all sheets into Results
Sheets("Old").Select
Range("a2", Cells(f, UniqueId)).Copy
Sheets("Results").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
Sheets("New").Select
Range("a2", Cells(s, UniqueId)).Copy
Sheets("Results").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
' Add in header info
Sheets("Results").Select
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
Sheets("Old").Select
Rows("1:1").Select
Selection.Copy
Sheets("Results").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
' Clean up added information
Sheets("New").Select
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("I:I").Select
Selection.Delete Shift:=xlToLeft
Sheets("Old").Select
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Columns("I:I").Select
Selection.Delete Shift:=xlToLeft
' Set conditional formatting
Sheets("Results").Select
Columns("J:J").Select
Cells.FormatConditions.Delete
Columns("J:J").Select
Selection.FormatConditions.AddUniqueValues
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).DupeUnique = xlDuplicate
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 6
End With
Selection.FormatConditions(1).StopIfTrue = False
' Filter and Clear duplicates
Range("J2", Range("J65536").End(xlUp)).Select
ActiveSheet.Range("J2", Range("J65536").End(xlUp)).AutoFilter Field:=1, Criteria1:=RGB(252, 243, 5), Operator:=xlFilterCellColor
Selection.EntireRow.Delete
ActiveWorkbook.Worksheets("Results").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Results").Sort.SortFields.Add Key:=Range("C2", Range("C65536").End(xlUp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Results").Sort.SortFields.Add Key:=Range("D2", Range("D65536").End(xlUp)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Results").Sort
.SetRange Range("A1", Range("J65536").End(xlUp))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' Loop until blank row found
n = 2
Do While Cells(n, 2).Value <> ""
Cells(n, 11).Value = "=IF(RC3<>R[-1]C3,IF(RC3<>R[1]C3,""New or Old"",""Dup""),""Dup"")"
n = n + 1
Loop
' Loop until blank row found
c = 2
Do While Cells(c, 2).Value <> ""
Cells(c, 12).Value = "=IF(RC[-1]=""New or Old"",IF(RC[-11]=""First"",""Cancelled"",""New""),""Version"")"
c = c + 1
Loop
' Coding Rows
Columns("L:L").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="New", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 4
End With
Selection.FormatConditions(1).StopIfTrue = False
Columns("L:L").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="Cancelled", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 3
End With
Selection.FormatConditions(1).StopIfTrue = False
Columns("L:L").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="Version", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ColorIndex = 6
End With
' Hide Extra Columns
Selection.FormatConditions(1).StopIfTrue = False
Columns("J:J").Select
Selection.EntireColumn.Hidden = True
Columns("K:K").Select
Selection.EntireColumn.Hidden = True
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
End Sub
Bookmarks