4.8 KiB
Month Quarter Product Category Selling unit Monthly Sales Quartely sales commission Monthly Margin Quaterly Margin Quaterly Commission January 1 4(Travel,Health,Life,Vehicle ) 33 155745 568575 70940.75 83204.25 207828.85 355946.15 Feburary 1 5(Travel,Health,Life,Vehicle,Accident) 55 280784 185388.75 93795.25 March 1 5(Travel,Health,Life,Vehicle,Accident) 42 132046 99616.65 30829.35 April 2 5(Travel,Health,Life,Vehicle,Accident) 52 148180 419345 105313.95 41266.05 151808.3 262736.7 May 2 5(Travel,Health,Life,Vehicle,Accident) 58 176290 112534.4 62155.6 June 2 4(Health,Life,Vehicle,Accident) 36 94875 44888.35 48386.65 July 3 4(Health,Life,Vehicle,Accident) 22 109074 329541 49322.3 58151.7 144782.3 179958.7 Augest 3 4(Travel,Health,Life,Accident) 37 96932 79387.2 15944.8 September 3 5(Travel,Health,Life,Vehicle,Accident) 27 123535 51249.2 70685.8 October 4 5(Travel,Health,Life,Vehicle,Accident) 43 87116 355452 80361.15 5154.85 52206.2 298445.8 November 4 4(Travel,Life,Vehicle,Accident) 34 51015 47483.9 1931.1 December 4 5(Travel,Health,Life,Vehicle,Accident) 54 217321 170600.75 45120.25
1. i need a excel function that will open a excel file named `D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Monthly & Quart\helloworld.xlsx`
2. check if sheet named `Sales Analysis Monthly & Quart` exist
2.1 if not exist create a sheet named `Sales Analysis Monthly & Quart`
2.2 if exist, empty the whole sheet
4. write Month first row as header of table
5. write Quarter first row as header of table
6. write Product Category first row as header of table
7. write Selling unit first row as header of table
8. write Monthly Sales first row as header of table
9. write Quartely sales first row as header of table
10. write commission first row as header of table
11. write Monthly Margin first row as header of table
12. write Quaterly Margin first row as header of table
13. write Quaterly Commission first row as header of table
14. write "January" at "A2"
15. write "Feburary" at "A3"
16. write "March" at "A4"
17. write "April" at "A5"
18. write "May" at "A6"
19. write "June" at "A7"
20. write "July" at "A8"
21. write "Augest" at "A9"
22. write "September" at "A10"
23. write "October" at "A11"
24. write "November" at "A12"
25. write "December" at "A13"
99. then close and save that excel file
thanks
Sub UpdateSalesAnalysisFile()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Monthly & Quart\helloworld.xlsx"
Const HEADER_ROW As Long = 1
Const START_CELL As String = "A2"
Dim wb As Workbook
Dim ws As Worksheet
Dim startCell As Range
' Open the workbook
Set wb = Workbooks.Open(FILE_PATH)
' Check if the sheet exists
On Error Resume Next
Set ws = wb.Sheets("Sales Analysis Monthly & Quart")
On Error GoTo 0
' If not found, create a new sheet
If ws Is Nothing Then
Set ws = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count))
ws.Name = "Sales Analysis Monthly & Quart"
Else
' Empty the entire sheet
ws.UsedRange.ClearContents
End If
' Write headers
With ws.Rows(HEADER_ROW)
.Cells(1).Value = "Month"
.Cells(2).Value = "Quarter"
.Cells(3).Value = "Product Category"
.Cells(4).Value = "Selling Unit"
.Cells(5).Value = "Monthly Sales"
.Cells(6).Value = "Quartely Sales"
.Cells(7).Value = "Commission"
.Cells(8).Value = "Monthly Margin"
.Cells(9).Value = "Quaterly Margin"
.Cells(10).Value = "Quaterly Commission"
End With
' Write month names
Set startCell = ws.Range(START_CELL)
Dim monthNames() As Variant
monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
Dim i As Long
For i = LBound(monthNames) To UBound(monthNames)
startCell.Offset(i, 0).Value = monthNames(i)
Next i
' Save and close the workbook
wb.Close SaveChanges:=True
End Sub
'column SALES_ANALYSIS_COL_MONTH = "A" SALES_ANALYSIS_COL_QUARTER = "B" SALES_ANALYSIS_COL_PRODUCT_CATEGORY = "C" SALES_ANALYSIS_COL_SELLING_UNIT = "D" SALES_ANALYSIS_COL_MONTHLY_SALES = "E" SALES_ANALYSIS_COL_QUARTELY_SALES = "F" SALES_ANALYSIS_COL_COMMISSION = "G" SALES_ANALYSIS_COL_MONTHLY_MARGIN = "H" SALES_ANALYSIS_COL_QUATERLY_MARGIN = "I" SALES_ANALYSIS_COL_QUATERLY_COMMISSION_ = "J"
'row SALES_ANALYSIS_ROW_JANUARY = "2" SALES_ANALYSIS_ROW_FEBURARY = "3" SALES_ANALYSIS_ROW_MARCH = "4" SALES_ANALYSIS_ROW_APRIL = "5" SALES_ANALYSIS_ROW_MAY = "6" SALES_ANALYSIS_ROW_JUNE = "7" SALES_ANALYSIS_ROW_JULY = "8" SALES_ANALYSIS_ROW_AUGEST = "9" SALES_ANALYSIS_ROW_SEPTEMBER = "10" SALES_ANALYSIS_ROW_OCTOBER = "11" SALES_ANALYSIS_ROW_NOVEMBER = "12" SALES_ANALYSIS_ROW_DECEMBER = "13"