Sub Workbook_Open()
Dim sFil As String
Dim sTitle As String
Dim sWb As String
Dim iFilterIndex As Integer
sTitle = "Raw Report"
sWb = Application.GetOpenFilename(sFil, iFilterIndex, sTitle)
Workbooks.Open Filename:=sWb
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Cells.Select
Application.Run "RunFirst.xls!FILTER"
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Cells.EntireColumn.AutoFit
Columns("D:D").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=OR(D1="""",D1>9999999)"
Selection.FormatConditions(1).Interior.ColorIndex = 37
Columns("E:E").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=NOT(ISNUMBER(E1))"
Selection.FormatConditions(1).Interior.ColorIndex = 37
Columns("H:H").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=OR(H1<200000000,H1>999999999)"
Selection.FormatConditions(1).Interior.ColorIndex = 37
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets.Add
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "To Be Corrected"
Dim wsO As Worksheet, wsD As Worksheet
Dim UR As Range, Crit As Range
Dim CritCol As Long
Set wsO = Sheets("Original")
Set wsD = Sheets("To Be Corrected")
Application.ScreenUpdating = False
wsD.UsedRange.Clear
With wsO
Set UR = wsO.UsedRange
CritCol = UR.Column + UR.Columns.Count
Set Crit = .Cells(1, CritCol).Resize(2)
Crit.Cells(2, 1).Formula = _
"=OR(D2="""",D2>9999999,NOT(ISNUMBER(E2)),H2<200000000,H2>999999999)"
UR.AdvancedFilter _
Action:=xlFilterInPlace, CriteriaRange:=Crit, Unique:=False
Crit.ClearContents
UR.SpecialCells(xlCellTypeVisible).Copy Destination:=wsD.Range("A1")
UR.Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error Resume Next
.ShowAllData
On Error GoTo 0
End With
Application.ScreenUpdating = True
End Sub