You are on page 1of 2

Sub Formateverything() Rem delete results sheet if it exists Dim ws As Worksheet For Each ws In Worksheets If ws.

Name = "Results" Then Application.DisplayAlerts = False Sheets("Results").Delete Application.DisplayAlerts = True End End If Next Rows("16:5000").Select Selection.Copy Sheets.Add.Name = "Results" Sheets("Results").Select Range("A1").Select ActiveSheet.Paste Rem Change all non-numeric numbers from text to numerical Cells.Select Selection.NumberFormat = "General" With ActiveSheet.UsedRange .Value = .Value End With 'End Sub 'Sub Sorteverything() Columns("L:L").Select Selection.NumberFormat = "[$-1009]mmmm d, yyyy;@" Rem Sort table according to specified columns. Note that this sequence should be piping-type-inspector-CML-inspection date 'Cells.Select ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("A:A") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("E:E") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("K:K") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("L:L") _ ' , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal ' ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("B:B") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal Rem since excel 2003 only allows for a 3 level sort, the sorting has to be done twice. Sort according to inspector, inspection date,CML,line,size Cells.Select Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Key2:=Range("C2") _ , Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _ xlSortNormal Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("A2") _ , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _

False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption 2 _ :=xlSortNormal Rem insert empty row into column for heading Rows("1:1").Select Selection.Insert Shift:=xlDown Rem copy heading for main report and paste as heading for sorted report Sheets("Report").Select Rows("16:16").Select Selection.Copy Sheets("Results").Select Rows("1:1").Select ActiveSheet.Paste Rem Freeze top heading Range("A2").Select ActiveWindow.FreezePanes = True Rem Autofit all selections Cells.Select Selection.Columns.autofit Rem center all results Cells.Select Application.CutCopyMode = False With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With End Sub

You might also like