Option Explicit
Sub runCTS()
'
Dim fname As String
fname = "\\mdzausutwfnp001\Shardata\Logistics\Reports\Compliance to Schedule\BI Report Dump\" & varCellvalue & ".xlsm"
'
'open the BI report
Application.ScreenUpdating = False
Dim varCellvalue As Long
varCellvalue = Range("D1").Value
Workbooks.Open "\\mdzausutwfnp001\Shardata\Logistics\Reports\Compliance to Schedule\BI Report Dump\" & varCellvalue & ".xlsm"
If Not ExistFile(fname) Then
MsgBox "File does not exist.", vbExclamation, "File Missing"
Exit Sub
Else
'select range of report to copy
Application.ScreenUpdating = False
Sheets("Table").Select
With Sheets("Table")
.Range("K16:Q1000" & .Cells(Rows.Count, 1).End(xlUp).Row).Select
End With
Selection.Copy
'select CTS workbook and paste
Windows("CTS Report Template.xlsm").Activate
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("BI Report Paste").Select
Application.DisplayAlerts = False
Workbooks(Range("D1").Value & ".xlsm").Close True
'Select range to convert to numbers
Sheets("BI Report Paste").Select
With Sheets("BI Report Paste")
.Range("A3:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Select
End With
'delete blank lines
Dim LR As Long
Application.ScreenUpdating = False
For LR = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("A" & LR).Value = "" Or Left(Range("A" & LR), 1) = "`" Then
Rows(LR).EntireRow.Delete
End If
Next LR
'convert selected range to number
On Error Resume Next
Application.ScreenUpdating = False
Dim Cell As Range
Selection.NumberFormat = "General"
For Each Cell In Selection
Cell.Value = Cell.Value * 1
Next Cell
Application.ScreenUpdating = True
'fill formulas down
Dim LastRow As Long
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Range("H3:M" & LastRow).FillDown
'show ABS Compliance and filter largest to smallest
ActiveSheet.Range("$A$2:$M$1000").AutoFilter Field:=11, Criteria1:="<=.9", _
Operator:=xlAnd
ActiveSheet.Range("$A$2:$M$1000").AutoFilter Field:=1, Criteria1:="<>"
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("BI Report Paste").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("BI Report Paste").AutoFilter.Sort.SortFields.Add _
Key:=Range("K2:K"), SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BI Report Paste").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Application.ScreenUpdating = False
'clear old data from report page
Sheets("Report").Select
Range("B32:C50").ClearContents
Range("E32:L50").ClearContents
'select the SKU cells from the filtered CTS report
Sheets("BI Report Paste").Select
With Sheets("BI Report Paste")
.Range("A3:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
End With
'paste the copied cells to the report sheet
Sheets("Report").Select
Range("B32").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'select the CTS Result cells from the filtered CTS report
Sheets("BI Report Paste").Select
With Sheets("BI Report Paste")
.Range("K3:K" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
End With
'paste the copied cells to the report sheet
Sheets("Report").Select
Range("c32").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'select the Description cells from the filtered CTS report
Sheets("BI Report Paste").Select
With Sheets("BI Report Paste")
.Range("B3:B" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy
End With
'paste the copied cells to the report sheet
Sheets("Report").Select
Range("E32").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("G32").Select
MsgBox ("CTS results will be copied to report page for you")
End If
End Sub