'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~Macro to process GCC Violation Report~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'***********Violations without Justification for specified Head of Credit**********
Sub Main1()
'***Variables***
Dim GCCReport As Workbook 'Workbook of report from GCC
Dim row_count As Integer 'no of rows written
'Delete data written in last import
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets("Start").Range("D32").ClearContents
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets("Sheet2").Range("B4:Q23000").Delete
'opens dialog box to choose report
Filename = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
If Filename = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open (Filename)
Set GCCReport = ActiveWorkbook
w_rows = DataExtract
GCCReport.Close
End If
MsgBox "Data Import has finished"
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets(2).Activate
row_count = RowCount
With Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets(2)
'Set Column Width
.Columns("A").ColumnWidth = 0
.Columns("B").ColumnWidth = 10
.Columns("C").ColumnWidth = 10
.Columns("D").ColumnWidth = 15
.Columns("E").ColumnWidth = 15
.Columns("F").ColumnWidth = 15
.Columns("G").ColumnWidth = 25
.Columns("H").ColumnWidth = 15
.Columns("I").ColumnWidth = 2
.Columns("J:L").ColumnWidth = 4
.Columns("J:L").HorizontalAlignment = xlCenter
.Columns("M").ColumnWidth = 4
.Columns("N").ColumnWidth = 25
.Columns("O").ColumnWidth = 20
.Columns("P").ColumnWidth = 7
'Set Row Height
.Rows("4:10000").AutoFit
'Set Borders
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.Weight = xlHairline
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.Color = RGB(0, 0, 0)
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.LineStyle = xlContinuous
' .Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Font.FontStyle = "Tahoma"
' .Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Font.Size = 10
.Range("A3:Q3").Borders.LineStyle = xlContinuous
.Range("A3:Q3").Borders.Weight = xlHairline
.Range("A3:Q3").Borders.Color = RGB(0, 0, 0)
End With
Call ColorUPC(4, row_count, 17, 5)
Call SeperateUPC(4, row_count, 17, 5, False)
Call DeleteJust(False, row_count)
Call PrintSetup(65, 2)
End Sub
'***********Violations with Justification for specified Head of Credit**********
Sub Main2()
'***Variables***
Dim GCCReport As Workbook 'Workbook of report from GCC
Dim row_count As Integer 'no of rows written
'Delete data written in last import
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets(1).Range("D32").ClearContents
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets("Sheet2").Range("B4:Q23000").Delete
'opens dialog box to choose report
Filename = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
If Filename = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open (Filename)
Set GCCReport = ActiveWorkbook
w_rows = DataExtract
GCCReport.Close
End If
MsgBox "Data Import has finished"
Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets(2).Activate
row_count = RowCount
With Workbooks("GCC Violation Report Filter MacroV2.1.xls").Worksheets(2)
'Set Column Width
.Columns("A").ColumnWidth = 0
.Columns("B").ColumnWidth = 10
.Columns("C").ColumnWidth = 10
.Columns("D").ColumnWidth = 15
.Columns("E").ColumnWidth = 15
.Columns("F").ColumnWidth = 15
.Columns("G").ColumnWidth = 25
.Columns("H").ColumnWidth = 15
.Columns("I").ColumnWidth = 2
.Columns("J:L").ColumnWidth = 4
.Columns("J:L").HorizontalAlignment = xlCenter
.Columns("M").ColumnWidth = 4
.Columns("N").ColumnWidth = 25
.Columns("O").ColumnWidth = 20
.Columns("P").ColumnWidth = 7
'Set Row Height
.Rows("4:10000").AutoFit
'Set Borders
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.Weight = xlHairline
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.Color = RGB(0, 0, 0)
.Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Borders.LineStyle = xlContinuous
' .Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Font.FontStyle = "Tahoma"
' .Range(Worksheets("Sheet2").Cells(4, 1), Worksheets("Sheet2").Cells(row_count, 17)).Font.Size = 10
.Range("A3:Q3").Borders.LineStyle = xlContinuous
.Range("A3:Q3").Borders.Weight = xlHairline
.Range("A3:Q3").Borders.Color = RGB(0, 0, 0)
End With
Call ColorUPC(4, row_count, 17, 5)
Call SeperateUPC(4, row_count, 17, 5, False)
Call DeleteJust(True, row_count)
Call PrintSetup(65, 2)
End Sub
'~~~~~Function to scan (active) Worksheet~~~~~
'returns row no in which entry was found if succesful, 0 else
'~~~~~Arguments~~~~~
'SearchValue the value you are looking for
'row_start row in which scan starts
'wb_to_scan Workbook which is scanned
'row_max maximal no of rows to be scanned
Private Function Scan(SearchValue, row_start As Integer, Optional wb_to_scan As Workbook, Optional row_max As Integer = 500) As Integer
'Column variable
Dim j As Integer
'sets column to search
'4 means Head for the credit
j = 4
'Loop Counter
Dim i As Integer
i = row_start
'Loop which scans the rows
Do
Dim Search1 As String
Search1 = SearchValue
Test1 = Worksheets("Sheet1").Cells(i, j).Value2
'MsgBox Test1 & " " & VarType(Test1) & " " & VarType(SearchValue)
If Test1 = Search1 Then
Scan = i
Exit Do
End If
If row_max < i Then
Scan = 0
Exit Do
End If
i = i + 1
Loop
End Function