Attribute VB_Name = "APAnalysisGraph" Function TeamATotalSalesCommisionPerformanceTable(ByVal calc_result As Variant, ByVal file_path As String) Dim wb As Workbook Dim ws As Worksheet Dim startCell As Range Dim monthly_commission As Variant Dim montyly_commission_TA As Variant ' team a monthly_commission = calc_result(1) montyly_commission_TA = calc_result(2) ' team a Dim monthNames() As Variant monthNames = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") ' Open the workbook Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") ' Write headers Set startCell = ws.Range("A1") startCell.Value = "Team A Total Sales Commision Performance" startCell.Offset(1, 0).Value = "Month" startCell.Offset(1, 1).Value = "Amount" Set startCell = ws.Range("A3") For m = LBound(monthNames) To UBound(monthNames) startCell.Offset(m, 0).Value = monthNames(m) startCell.Offset(m, 1).Value = montyly_commission_TA(m + 1) Next m ' Save and close the workbook ' wb.Close SaveChanges:=True End Function Function TeamBTotalSalesCommisionPerformanceTable(ByVal calc_result As Variant, ByVal file_path As String) Dim wb As Workbook Dim ws As Worksheet Dim startCell As Range Dim monthly_commission As Variant Dim montyly_commission_TB As Variant ' team b monthly_commission = calc_result(1) montyly_commission_TB = calc_result(3) ' team b Dim monthNames() As Variant monthNames = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") ' Open the workbook Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") ' Write headers Set startCell = ws.Range("A20") startCell.Value = "Team B Total Sales Commision Performance" startCell.Offset(1, 0).Value = "Month" startCell.Offset(1, 1).Value = "Amount" Set startCell = ws.Range("A22") For m = LBound(monthNames) To UBound(monthNames) startCell.Offset(m, 0).Value = monthNames(m) startCell.Offset(m, 1).Value = montyly_commission_TB(m + 1) Next m ' Save and close the workbook ' wb.Close SaveChanges:=True End Function Function TeamATotalSalesCommisionPerformanceGraph(ByVal calc_result As Variant, ByVal file_path As String) Dim wb As Workbook Dim ws As Worksheet Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") Dim cht As Chart Dim ax As Axis ' insert graph ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select Set cho = ws.ChartObjects(ws.ChartObjects.Count) Set cht = cho.Chart cht.SetSourceData Source:=Range("A2:B14") ' update chart styling cht.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis) Selection.Format.TextFrame2.TextRange.Characters.Text = "Month" cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis) cht.ChartTitle.Text = "Team A total Sales commision performance" Set ax = cht.Axes(xlValue, xlPrimary) ax.HasTitle = True ax.AxisTitle.Format.TextFrame2.TextRange.Characters.Text = "Amount" cho.Top = 0 cho.Left = 0 cho.Width = 400 cho.Height = 300 End Function Function TeamBTotalSalesCommisionPerformanceGraph(ByVal calc_result As Variant, ByVal file_path As String) Dim wb As Workbook Dim ws As Worksheet Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") Dim cht As Chart Dim ax As Axis ' insert graph ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select Set cho = ws.ChartObjects(ws.ChartObjects.Count) Set cht = cho.Chart cht.SetSourceData Source:=Range("A21:B33") ' update chart styling cht.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis) Selection.Format.TextFrame2.TextRange.Characters.Text = "Month" cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis) cht.ChartTitle.Text = "Team B total Sales commision performance" Set ax = cht.Axes(xlValue, xlPrimary) ax.HasTitle = True ax.AxisTitle.Format.TextFrame2.TextRange.Characters.Text = "Amount" cho.Top = 300 cho.Left = 0 cho.Width = 400 cho.Height = 300 End Function Function RankOfAgentSalesCommMonthlyTable(ByVal calc_result As Variant, ByVal file_path As String) Const HEADER_ROW As Long = 1 Const START_CELL As String = "F1" Dim wb As Workbook Dim ws As Worksheet Dim startCell As Range Dim monthly_top_5_comission_name As Variant Dim monthly_top_5_comission_value As Variant monthly_top_5_comission_name = calc_result(6) monthly_top_5_comission_value = calc_result(7) ' Open the workbook Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") ' Write headers Set startCell = ws.Range(START_CELL) startCell.Offset(0, 0).Value = "Top 5 Agent's Commssion" 'generate graph by month For m = LBound(MONTH_NAMES) To UBound(MONTH_NAMES) startCell.Offset(1, 0 + (m * 3)).Value = "Name" startCell.Offset(1, 1 + (m * 3)).Value = "Commssion" startCell.Offset(1 + 1, 0 + (m * 3)).Value = monthly_top_5_comission_name(m + 1, 0) startCell.Offset(1 + 2, 0 + (m * 3)).Value = monthly_top_5_comission_name(m + 1, 1) startCell.Offset(1 + 3, 0 + (m * 3)).Value = monthly_top_5_comission_name(m + 1, 2) startCell.Offset(1 + 4, 0 + (m * 3)).Value = monthly_top_5_comission_name(m + 1, 3) startCell.Offset(1 + 5, 0 + (m * 3)).Value = monthly_top_5_comission_name(m + 1, 4) startCell.Offset(1 + 1, 1 + (m * 3)).Value = monthly_top_5_comission_value(m + 1, 0) startCell.Offset(1 + 2, 1 + (m * 3)).Value = monthly_top_5_comission_value(m + 1, 1) startCell.Offset(1 + 3, 1 + (m * 3)).Value = monthly_top_5_comission_value(m + 1, 2) startCell.Offset(1 + 4, 1 + (m * 3)).Value = monthly_top_5_comission_value(m + 1, 3) startCell.Offset(1 + 5, 1 + (m * 3)).Value = monthly_top_5_comission_value(m + 1, 4) Next m ' Save and close the workbook ' wb.Close SaveChanges:=True End Function Function RankOfAgentSalesCommMonthlyGraph(ByVal calc_result As Variant, ByVal file_path As String) Dim wb As Workbook Dim ws As Worksheet Set wb = Workbooks.Open(file_path) Set ws = wb.Sheets("Agent performance analysis") Dim DATA_RANGES As Variant DATA_RANGES = Array("F2:G7", "I2:J7", "L2:M7", "O2:P7", "R2:S7", "U2:V7", "X2:Y7", "AA2:AB7", "AD2:AE7", "AG2:AH7", "AJ2:AK7", "AM2:AN7") Dim GRAPH_TOPS As Variant Dim GRAPH_LEFTS As Variant GRAPH_TOPS = Array(0, 0, 0, 200, 200, 200, 400, 400, 400, 600, 600, 600) GRAPH_LEFTS = Array(400, 700, 1000, 400, 700, 1000, 400, 700, 1000, 400, 700, 1000) 'generate graph by month For m = LBound(MONTH_NAMES) To UBound(MONTH_NAMES) month_name = MONTH_NAMES(m) ' insert graph ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select Set cho = ws.ChartObjects(ws.ChartObjects.Count) Set cht = cho.Chart ActiveChart.SetSourceData Source:=Range(DATA_RANGES(m)) ActiveChart.ChartTitle.Text = "Top 5 Sales Commission " & month_name ' update chart styling cht.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis) Selection.Format.TextFrame2.TextRange.Characters.Text = "Name" cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis) Set ax = cht.Axes(xlValue, xlPrimary) ax.HasTitle = True ax.AxisTitle.Format.TextFrame2.TextRange.Characters.Text = "Commission" cho.Top = GRAPH_TOPS(m) cho.Left = GRAPH_LEFTS(m) cho.Width = 300 cho.Height = 200 Next m End Function Function Helloworld() Debug.Print "helloworld Sales_Analysis_Product_Category" End Function