This commit is contained in:
louiscklaw
2025-01-31 21:36:48 +08:00
parent 8ee1ccbebc
commit 2e592cb561
248 changed files with 11958 additions and 0 deletions

View File

@@ -0,0 +1,224 @@
January Feburary March April May June July Augest September October November December
Alex 11329 0 9088.2 9954 16537.2 1166.55 1269.2 1324 1767.2 3950.3 0 16653.2
Ben 0 7321.6 1450.5 1931.2 5299.9 10666.8 0 373.5 0 0 0 0
Candy 27546.75 0 0 0 0 7993.8 12959.4 8533.35 4377.6 31058 724.5 16883.1
Danny 7357 47805 13873.75 9885.85 9548 11063.8 152.1 4791.2 7437.5 16389.75 147.9 499.5
Eason 2882.4 12648.75 17099.95 5186.4 15248.8 3102.4 30012 5036 0 67.5 8676.9 0
Filex 5830.8 46820.5 31655.7 4291.8 9886.4 1152 0 8010.8 11494.15 1373.7 11113.2 63684.8
Gary 0 17772.8 26407.05 36516.8 678.7 648 0 7515.25 1578.45 1116 73.5 39.5
Henry 0 0 41.5 18345.3 23600.3 1238.4 538.4 19172.55 0 550.8 21873.6 579.9
Irene 0 32649.9 0 12510.6 27206.7 7856.6 2204.85 24630.55 847.8 9049.5 681.3 62511.75
Jenny 15994.8 20370.2 0 6692 4528.4 0 2186.35 0 23746.5 16805.6 4193 9749
Total 70940.75 185388.75 99616.65 105313.95 112534.4 44888.35 49322.3 79387.2 51249.2 80361.15 47483.9 170600.75
Team A total 49115.15 67775.35 41512.4 26957.45 46633.9 33993.35 44392.7 20058.05 13582.3 51465.55 9549.3 34035.8
Team B Total 21825.6 117613.4 58104.25 78356.5 65900.5 10895 4929.6 59329.15 37666.9 28895.6 37934.6 136564.95
Team A Quartely 158402.9 107584.7 78033.05 95050.65
Team B Quartely 197543.25 155152 101925.65 203395.15
Rank for Each Month
January February March April May June
1 Candy 8987.85 Danny 14903.5 Filex 10551.9 Gary 10323.2 Irene 11178 Danny 4942.2
2 Alex 5441.5 Filex 14005.8 Gary 9802.45 Henry 5876.7 Alex 6870 Irene 3928.3
3 Jenny 5358.6 Irene 8218.5 Eason 5239.85 Irene 5267.1 Henry 6623.8 Ben 3555.6
4 Danny 3678.5 Jenny 6956.3 Danny 3529.75 Danny 4926.85 Eason 3875.2 Candy 2664.6
5 Filex 2996.4 Eason 5418.45 Alex 3029.4 Alex 3380.4 Ben 3011.6 Eason 1551.2
July August September October November December
1 Eason 7704.6 Henry 7242.35 Jenny 9490.2 Candy 8743.2 Henry 5468.4 Irene 18256.05
2 Candy 4339.8 Irene 6562.15 Filex 4535.35 Danny 5505.75 Filex 3704.4 Filex 16776.4
3 Irene 2204.85 Filex 4005.4 Danny 2949.8 Irene 4360.5 Eason 2892.3 Candy 5627.7
4 Jenny 2085.85 Gary 3149.35 Candy 1836 Jenny 4201.4 Jenny 1241.2 Alex 4661.8
5 Alex 1269.2 Candy 2844.45 Gary 1578.45 Alex 2773.1 Irene 681.3 Jenny 2540
```prompt
1. i need a excel function that will open a excel file named `D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\helloworld.xlsx`
2. check if sheet named `Sales Analysis Product Category` exist
2.1 if not exist create a sheet named `Sales Analysis Product Category`
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
```
```vb
Sub AgentPerformanceAnalysisComm()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Agent performance analysis\helloworld.xlsx"
Const TOP_ROW As Long = 1
Const START_CELL As String = "A2"
Dim wb As Workbook
Dim ws As Worksheet
Dim startCell As Range
Dim tempArray() as Variant
Dim i As Long
' Open the workbook
Set wb = Workbooks.Open(FILE_PATH)
' Check if the sheet exists
On Error Resume Next
Set ws = wb.Sheets("Agent performance analysis(Comm")
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 = "Agent performance analysis(Comm"
Else
' Empty the entire sheet
ws.UsedRange.ClearContents
End If
' Write month names
Set startCell = ws.Range("B1")
tempArray = Array("January","Feburary","March","April","May","June","July","Augest","September","October","November","December")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(0, i).Value = tempArray(i)
Next i
' Write month names
Set startCell = ws.Range("A2")
tempArray = Array("Alex","Ben","Candy","Danny","Eason","Filex","Gary","Henry","Irene","Jenny")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = tempArray(i)
Next i
' Write month names
Set startCell = ws.Range("A16")
Dim tempArray() As Variant
tempArray = Array("Total","","Team A total", "Team B Total", "Team A Quartely", "Team B Quartely")
Dim i As Long
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = tempArray(i)
Next i
' Save and close the workbook
wb.Close SaveChanges:=True
End Sub
```
```vb
Sub AgentPerformanceAnalysisCommRankForEachMonth()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Agent performance analysis\helloworld.xlsx"
Const TOP_ROW As Long = 21
Const START_CELL As String = "A2"
Dim wb As Workbook
Dim ws As Worksheet
Dim startCell As Range
Dim i As Long
Dim tempArray() as Variant
' Open the workbook
Set wb = Workbooks.Open(FILE_PATH)
' Check if the sheet exists
On Error Resume Next
Set ws = wb.Sheets("Agent performance analysis(Comm")
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 = "Agent performance analysis(Comm"
Else
' Empty the entire sheet
' ws.UsedRange.ClearContents
End If
' Write headers
With ws.Rows(TOP_ROW)
.Cells(1).Value = "Rank for Each Month"
End With
' Write month names
Set startCell = ws.Range("A23")
tempArray = Array("1","2","3","4","5")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = i+1
Next i
Set startCell = ws.Range("B22")
tempArray = Array("January","Feburary","March","April","May","June")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(0, i*2).Value = tempArray(i)
Next i
Set startCell = ws.Range("A30")
tempArray = Array("1","2","3","4","5")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = i+1
Next i
Set startCell = ws.Range("B29")
tempArray = Array("July","Augest","September","October","November","December")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(0, i*2).Value = tempArray(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"

View File

@@ -0,0 +1,140 @@
Case Persistency
Name No of new case No. of collpased case Case Persistency
Alex 46 14 53.33%
Ben 20 14 17.65%
Candy 49 11 63.33%
Danny 55 9 71.88%
Eason 49 11 63.33%
Filex 70 27 44.33%
Gary 41 3 86.36%
Henry 44 1 95.56%
Irene 60 17 55.84%
Jenny 59 16 57.33%
Team A total 219 59 57.55%
Team B Total 274 64 62.13%
```prompt
1. i need a excel function that will open a excel file named `D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\helloworld.xlsx`
2. check if sheet named `Sales Analysis Product Category` exist
2.1 if not exist create a sheet named `Sales Analysis Product Category`
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
```
```vb
Sub NoOfCases()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\No of cases\helloworld.xlsx"
Const TOP_ROW As Long = 1
Dim wb As Workbook
Dim ws As Worksheet
Dim startCell As Range
Dim tempArray() as Variant
Dim i As Long
' Open the workbook
Set wb = Workbooks.Open(FILE_PATH)
' Check if the sheet exists
On Error Resume Next
Set ws = wb.Sheets("No. of cases")
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 = "No. of cases"
Else
' Empty the entire sheet
ws.UsedRange.ClearContents
End If
' Write month names
Set startCell = ws.Range("A1")
tempArray = Array("Case Persistency")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(0, i).Value = tempArray(i)
Next i
' Write month names
Set startCell = ws.Range("A2")
tempArray = Array("Name","No of new case","No. of collpased case","Case Persistency")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(0, i).Value = tempArray(i)
Next i
' Write month names
Set startCell = ws.Range("A3")
tempArray = Array("Alex","Ben","Candy","Danny","Eason","Filex","Gary","Henry","Irene","Jenny")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = tempArray(i)
Next i
' Write month names
Set startCell = ws.Range("A14")
tempArray = Array("Team A total", "Team B Total")
For i = LBound(tempArray) To UBound(tempArray)
startCell.Offset(i, 0).Value = tempArray(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"

Binary file not shown.

View File

@@ -0,0 +1,132 @@
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
```prompt
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
```
```vb
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"

View File

@@ -0,0 +1,142 @@
Sales Amount Month
January Feburary March April May June July Augest September October November December
Product Category Travel insurance 10510 62040 52537 59655 39932 4432 0 63276 11445 56737 26208 67394
Health insurance 14172 56018 35580 52585 77964 54972 30437 q 31729 22729 13224 40309
Life insurance 6962 875 1377 5666 3260 2712 1933 1644 2714 5754 3827 1891
Vehicle insurance 123047 160363 39477 28991 53202 31399 75485 0 77647 0 4542 105009
Accident insurance 1054 1488 3075 1283 1932 1360 1219 2612 0 1896 3214 2718
Monthly Total 155745 280784 132046 148180 176290 94875 109074 67532 123535 87116 51015 217321
Quaterly Total 568575 419345 300141 355452
Sales Unit
January Feburary March April May June July Augest September October November December
Product Category Travel insurance 2 20 14 13 18 2 0 18 5 15 7 15
Health insurance 21 41 8 15 14 12 5 5 6 5 3 10
Life insurance 22 31 3 12 8 11 4 3 9 16 9 5
Vehicle insurance 27 15 6 5 7 3 6 0 7 0 1 11
Accident insurance 24 26 11 7 11 8 7 11 0 7 14 13
Monthly Total 96 133 42 52 58 36 22 37 27 43 34 54
Quarterly Total 271 146 86 131
```prompt
1. i need a excel function that will open a excel file named `D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\helloworld.xlsx`
2. check if sheet named `Sales Analysis Product Category` exist
2.1 if not exist create a sheet named `Sales Analysis Product Category`
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
```
```vb
Sub UpdateSalesAnalysisFileSalesUnit()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\helloworld.xlsx"
Const TOP_ROW As Long = 10
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(TOP_ROW)
.Cells(1).Value = "Sales Unit"
.Cells(3).Value = "Month"
End With
' Write month names
Set startCell = ws.Range("C11")
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(0, i).Value = monthNames(i)
Next i
' Write headers
With ws.Rows(12)
.Cells(1).Value = "Product Category"
End With
' Write sub-column names
Set startCell = ws.Range("B12")
Dim subColumn() As Variant
subColumn = Array("Travel insurance", "Health insurance", "Life insurance", "Vehicle insurance", "Accident insurance", "Monthly Total", "Quaterly Total")
For i = LBound(subColumn) To UBound(subColumn)
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"

View File

@@ -0,0 +1,142 @@
Sales Amount Month
January Feburary March April May June July Augest September October November December
Product Category Travel insurance 10510 62040 52537 59655 39932 4432 0 63276 11445 56737 26208 67394
Health insurance 14172 56018 35580 52585 77964 54972 30437 q 31729 22729 13224 40309
Life insurance 6962 875 1377 5666 3260 2712 1933 1644 2714 5754 3827 1891
Vehicle insurance 123047 160363 39477 28991 53202 31399 75485 0 77647 0 4542 105009
Accident insurance 1054 1488 3075 1283 1932 1360 1219 2612 0 1896 3214 2718
Monthly Total 155745 280784 132046 148180 176290 94875 109074 67532 123535 87116 51015 217321
Quaterly Total 568575 419345 300141 355452
Sales Unit
January Feburary March April May June July Augest September October November December
Product Category Travel insurance 2 20 14 13 18 2 0 18 5 15 7 15
Health insurance 21 41 8 15 14 12 5 5 6 5 3 10
Life insurance 22 31 3 12 8 11 4 3 9 16 9 5
Vehicle insurance 27 15 6 5 7 3 6 0 7 0 1 11
Accident insurance 24 26 11 7 11 8 7 11 0 7 14 13
Monthly Total 96 133 42 52 58 36 22 37 27 43 34 54
Quarterly Total 271 146 86 131
```prompt
1. i need a excel function that will open a excel file named `D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\helloworld.xlsx`
2. check if sheet named `Sales Analysis Product Category` exist
2.1 if not exist create a sheet named `Sales Analysis Product Category`
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
```
```vb
Sub UpdateSalesAnalysisFileSalesAmount()
Const FILE_PATH As String = "D:\_workspace\carousell-comission-playlist\jimmycheung93\task4\_poc\Sales Analysis Product Category\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 = "Sales Amount"
.Cells(3).Value = "Month"
End With
' Write month names
Set startCell = ws.Range("C2")
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(0, i).Value = monthNames(i)
Next i
' Write headers
With ws.Rows(3)
.Cells(1).Value = "Product Category"
End With
' Write sub-column names
Set startCell = ws.Range("B3")
Dim subColumn() As Variant
subColumn = Array("Travel insurance", "Health insurance", "Life insurance", "Vehicle insurance", "Accident insurance", "Monthly Total", "Quaterly Total")
For i = LBound(subColumn) To UBound(subColumn)
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"