178 lines
4.9 KiB
QBasic
178 lines
4.9 KiB
QBasic
Attribute VB_Name = "SAMonthAndQuartGraph"
|
|
|
|
|
|
Function MonthlySalesAmountTable(ByVal calc_result As Variant, ByVal FILE_PATH As String)
|
|
' monthly_product_category,
|
|
' monthly_selling_unit,
|
|
' monthly_sales,
|
|
' quaterly_sales,
|
|
' monthly_commission,
|
|
' monthly_margin,
|
|
' quaterly_margin,
|
|
' quaterly_comission
|
|
Const HEADER_ROW As Long = 1
|
|
Const START_CELL As String = "A1"
|
|
Dim wb As Workbook
|
|
Dim ws As Worksheet
|
|
Dim startCell As Range
|
|
|
|
' Open the workbook
|
|
Set wb = Workbooks.Open(FILE_PATH)
|
|
Set ws = wb.Sheets("Sales Analysis Monthly_Quartery")
|
|
|
|
' Write headers
|
|
Set startCell = ws.Range(START_CELL)
|
|
With startCell
|
|
.Value = "Monthly Sales Amount in 2023"
|
|
End With
|
|
|
|
With startCell
|
|
.Offset(1, 0).Value = "date"
|
|
.Offset(1, 1).Value = "Monthly Sales"
|
|
End With
|
|
|
|
Set startCell = ws.Range("A3")
|
|
Dim monthNames() As Variant
|
|
monthNames = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
|
|
|
|
monthly_sales = calc_result(2)
|
|
|
|
For m = LBound(monthNames) To UBound(monthNames)
|
|
startCell.Offset(m, 0).Value = monthNames(m)
|
|
startCell.Offset(m, 1).Value = monthly_sales(m + 1)
|
|
Next m
|
|
|
|
|
|
' TODO: replace content to real data
|
|
|
|
|
|
|
|
' Save and close the workbook
|
|
' wb.Close SaveChanges:=True
|
|
End Function
|
|
|
|
|
|
Function MonthlySalesAmountGraph(ByVal FILE_PATH As String)
|
|
Dim wb As Workbook
|
|
Dim ws As Worksheet
|
|
|
|
Set wb = Workbooks.Open(FILE_PATH)
|
|
Set ws = wb.Sheets("Sales Analysis Monthly_Quartery")
|
|
|
|
Range("A2:B14").Select
|
|
ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
|
|
ActiveChart.SetSourceData Source:=Range("$A$2:$B$14")
|
|
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
|
|
Selection.Format.TextFrame2.TextRange.Characters.Text = "Date range"
|
|
|
|
Set cho = ws.ChartObjects(1)
|
|
Set cht = cho.Chart
|
|
cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
|
|
|
|
'# set your axis in a variable
|
|
Set ax = cht.Axes(xlValue, xlPrimary)
|
|
'# Make sure your axis HAS a title
|
|
ax.HasTitle = True
|
|
With ax.AxisTitle.Format.TextFrame2.TextRange
|
|
.Characters.Text = "Primary Y-Axis"
|
|
With .Characters(1, 14).ParagraphFormat
|
|
.TextDirection = msoTextDirectionLeftToRight
|
|
.Alignment = msoAlignCenter
|
|
End With
|
|
End With
|
|
|
|
cho.Top = 0
|
|
cho.Left = 0
|
|
cho.Width = 400
|
|
cho.Height = 300
|
|
|
|
End Function
|
|
|
|
|
|
Function MonthlySalesComissionTable(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
|
|
|
|
' Open the workbook
|
|
Set wb = Workbooks.Open(FILE_PATH)
|
|
Set ws = wb.Sheets("Sales Analysis Monthly_Quartery")
|
|
|
|
' Write headers
|
|
Set startCell = ws.Range(START_CELL)
|
|
With startCell
|
|
.Value = "Monthly Sales Comission in 2023"
|
|
End With
|
|
|
|
With startCell
|
|
.Offset(1, 0).Value = "date"
|
|
.Offset(1, 1).Value = "Monthly Sales Commission"
|
|
End With
|
|
|
|
Set startCell = ws.Range("F3")
|
|
Dim monthNames() As Variant
|
|
monthNames = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
|
|
|
|
monthly_commission = calc_result(4)
|
|
For m = LBound(monthNames) To UBound(monthNames)
|
|
startCell.Offset(m, 0).Value = monthNames(m)
|
|
startCell.Offset(m, 1).Value = monthly_commission(m + 1)
|
|
Next m
|
|
|
|
|
|
' TODO: replace content to real data
|
|
|
|
' Save and close the workbook
|
|
' wb.Close SaveChanges:=True
|
|
End Function
|
|
|
|
|
|
Function MonthlySalesComissionGraph(ByVal FILE_PATH As String)
|
|
Dim wb As Workbook
|
|
Dim ws As Worksheet
|
|
|
|
Set wb = Workbooks.Open(FILE_PATH)
|
|
Set ws = wb.Sheets("Sales Analysis Monthly_Quartery")
|
|
|
|
ActiveSheet.Shapes.AddChart2(332, xlLineMarkers).Select
|
|
ActiveChart.SetSourceData Source:=Range("$F$2:$G$14")
|
|
|
|
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
|
|
Selection.Format.TextFrame2.TextRange.Characters.Text = "Date range chart2"
|
|
|
|
Set cho = ws.ChartObjects(2)
|
|
Set cht = cho.Chart
|
|
cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
|
|
|
|
'# set your axis in a variable
|
|
Set ax = cht.Axes(xlValue, xlPrimary)
|
|
'# Make sure your axis HAS a title
|
|
ax.HasTitle = True
|
|
With ax.AxisTitle.Format.TextFrame2.TextRange
|
|
.Characters.Text = "Primary Y-Axis"
|
|
With .Characters(1, 14).ParagraphFormat
|
|
.TextDirection = msoTextDirectionLeftToRight
|
|
.Alignment = msoAlignCenter
|
|
End With
|
|
End With
|
|
|
|
cho.Top = 0
|
|
cho.Left = 400
|
|
cho.Width = 400
|
|
cho.Height = 300
|
|
|
|
End Function
|
|
|
|
|
|
Function Helloworld()
|
|
Debug.Print "helloworld SalesAnalysisMonthAndQuartGraph"
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|