Hi Jacob,
Another question if I may. I have modified the macro to do a bit more.
Sub Add_Col_Row()
Dim LastRow As Long
Dim LastCol As Long
Dim i As Long
Dim j As Long
Rows("1:1").Orientation = 90
ActiveWindow.SplitRow = 1
ActiveWindow.FreezePanes = True
Cells.Columns.AutoFit
LastRow = Cells.Find(What:="*", LookIn:=xlValues, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
LastCol = Cells.Find(What:="*", LookIn:=xlValues, _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
For i = 5 To 6
Range(Cells(LastRow, i).Address).Value = _
"=Count(" & Cells(2, i).Address(False, False) & ":" & _
Cells(LastRow - 1, i).Address(False, False) & ")"
Next i
Range("E" & LastRow & ":F" & LastRow).AutoFill _
Destination:=Range("E" & LastRow & ":" & _
Cells(LastRow, LastCol - 1).Address(False, False)), Type:=xlFillDefault
For i = 2 To 3
Cells(i, LastCol).Value = "=Min(" & Range("E" & i & _
":" & Cells(i, LastCol - 1).Address).Address(False, False) & ")"
Next i
Range(Cells(2, LastCol).Address & ":" & Cells(3, LastCol).Address).AutoFill _
Destination:=Range(Cells(2, LastCol).Address & ":" & _
Cells(LastRow, LastCol).Address), Type:=xlFillDefault
For i = 2 To 3
Cells(i, LastCol + 1).Value = "=Count(" & Range("E" & i & _
":" & Cells(i, LastCol - 1).Address).Address(False, False) & ")"
Next i
Range(Cells(2, LastCol + 1).Address & ":" & Cells(3, LastCol + 1).Address).AutoFill _
Destination:=Range(Cells(2, LastCol + 1 ).Address & ":" & _
Cells(LastRow, LastCol + 1).Address), Type:=xlFillDefault
Cells(LastRow, LastCol + 1).ClearContents
Cells(LastRow, LastCol).ClearContents
Cells(1,LastCol + 1).Value = "number of corners with violations"
Cells(1,LastCol).Value = "largest violations"
Cells(LastRow, 2).Value = "number of violations per corner"
Columns(LastCol).Select
Selection.Sort Key1:=Range(LastCol), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Insert Shift:=xlToRight
End Sub
The sort doesn't appear to work - well it sorts but then gives me an error
Runtime error 1004
Method Rang of object _Global failed
and does not do the next line of inserting the column.
Any ideas?
Thanks,
Mick