Want to generate tables from column of data thru VBA.

AGU

New Member
Joined
Apr 24, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi guys, good day to all. Hope you all are ok. Guys I would like to generate a sales report from column of data. Normally I use a pivot table, but I need to automate this by using VBA. Basically, there's a new entry for every time someone uses a sales report. What I'd want is VBA creating three tables using data from data sheet similar to the functionality of a pivot table. I have tried some code, I'm trying to use array formula, but I am unable to take out unique values. Here is a code I have so far & additional help will be greatly appreciated.

Sub test10()

Dim Arr As Variant
Arr = Sheets("SalesOrders").Cells(1).CurrentRegion

Dim i As Long
For i = LBound(Arr, 1) + 1 To UBound(Arr, 1)
Next i

Sheets("sheet1").Range("C4").CurrentRegion.ClearContents

Dim rowcount As Long, columncount As Long
rowcount = UBound(Arr, 1)
columncount = UBound(Arr, 2)

Sheets("sheet1").Range("c4").Resize(rowcount, columncount).Value = Arr

End Sub

Sales Orders Summary
RegionS#Rep Total Total% Unit Cost Unit Cost%
Central1Andrews4382%101%
2Gill1,7509%415%
3Jardine2,81214%405%
4Kivell3,10916%17420%
5Morgan1,3887%263%
6Smith1,6418%14116%
East7Howard5373%71%
8Jones2,36312%566%
9Parent3,10216%566%
West10Sorvino1,2847%30034%
11Thompson1,2036%223%
Total19,628100%873100%
Region Total Total% Unit Cost Unit Cost%
Central11,13957%43250%
East6,00231%11914%
West2,48713%32237%
Total19,628100%873100%
Item Total Total% Unit Cost Unit Cost%
Binder9,57849%17320%
Desk1,7009%52560%
Pen2,04510%566%
Pen Set4,17021%8310%
Pencil2,13511%364%
Total19,628100%873100%



Sales Report Jan 2022 (Project).xls
ABCDEF
1RegionRepItemUnitsUnit CostTotal
2CentralSmithDesk2125.00250.00
3CentralKivellDesk5125.00625.00
4CentralGillPencil71.299.03
5CentralJardineBinder114.9954.89
6CentralAndrewsPencil141.2918.06
7CentralGillPen2719.99539.73
8CentralMorganBinder288.99251.72
9CentralAndrewsBinder284.99139.72
10CentralJardinePencil364.99179.64
11CentralKivellPen Set4223.951,005.90
12CentralGillBinder468.99413.54
13CentralKivellBinder5019.99999.50
14CentralJardinePen Set504.99249.50
15CentralGillPencil531.2968.37
16CentralMorganPen Set5512.49686.95
17CentralAndrewsPencil661.99131.34
18CentralSmithPencil671.2986.43
19CentralAndrewsPencil751.99149.25
20CentralGillBinder808.99719.20
21CentralSmithBinder8715.001,305.00
22CentralJardinePencil904.99449.10
23CentralMorganPencil904.99449.10
24CentralJardineBinder9419.991,879.06
25CentralKivellPen Set964.99479.04
26EastJonesBinder44.9919.96
27EastParentPen1519.99299.85
28EastJonesPen Set1615.99255.84
29EastHowardBinder291.9957.71
30EastJonesPencil354.99174.65
31EastJonesBinder604.99299.40
32EastJonesBinder608.99539.40
33EastJonesPen Set624.99309.38
34EastJonesPen648.99575.36
35EastParentPen Set7415.991,183.26
36EastParentBinder8119.991,619.19
37EastJonesPencil951.99189.05
38EastHowardPen964.99479.04
39WestSorvinoDesk3275.00825.00
40WestSorvinoBinder719.99139.93
41WestThompsonPencil321.9963.68
42WestSorvinoPencil562.99167.44
43WestThompsonBinder5719.991,139.43
44WestSorvinoPen761.99151.24
SalesOrders
Cell Formulas
RangeFormula
F2:F44F2=E2*D2
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi guys, good day to all. Hope you all are ok. Guys I would like to generate a sales report from column of data. Normally I use a pivot table, but I need to automate this by using VBA. Basically, there's a new entry for every time someone uses a sales report. What I'd want is VBA creating three tables using data from data sheet similar to the functionality of a pivot table. I have tried some code, I'm trying to use array formula, but I am unable to take out unique values. Here is a code I have so far & additional help will be greatly appreciated.

Sub test10()

Dim Arr As Variant
Arr = Sheets("SalesOrders").Cells(1).CurrentRegion

Dim i As Long
For i = LBound(Arr, 1) + 1 To UBound(Arr, 1)
Next i

Sheets("sheet1").Range("C4").CurrentRegion.ClearContents

Dim rowcount As Long, columncount As Long
rowcount = UBound(Arr, 1)
columncount = UBound(Arr, 2)

Sheets("sheet1").Range("c4").Resize(rowcount, columncount).Value = Arr

End Sub

Sales Orders Summary
RegionS#Rep Total Total% Unit Cost Unit Cost%
Central1Andrews4382%101%
2Gill1,7509%415%
3Jardine2,81214%405%
4Kivell3,10916%17420%
5Morgan1,3887%263%
6Smith1,6418%14116%
East7Howard5373%71%
8Jones2,36312%566%
9Parent3,10216%566%
West10Sorvino1,2847%30034%
11Thompson1,2036%223%
Total19,628100%873100%
Region Total Total% Unit Cost Unit Cost%
Central11,13957%43250%
East6,00231%11914%
West2,48713%32237%
Total19,628100%873100%
Item Total Total% Unit Cost Unit Cost%
Binder9,57849%17320%
Desk1,7009%52560%
Pen2,04510%566%
Pen Set4,17021%8310%
Pencil2,13511%364%
Total19,628100%873100%



Sales Report Jan 2022 (Project).xls
ABCDEF
1RegionRepItemUnitsUnit CostTotal
2CentralSmithDesk2125.00250.00
3CentralKivellDesk5125.00625.00
4CentralGillPencil71.299.03
5CentralJardineBinder114.9954.89
6CentralAndrewsPencil141.2918.06
7CentralGillPen2719.99539.73
8CentralMorganBinder288.99251.72
9CentralAndrewsBinder284.99139.72
10CentralJardinePencil364.99179.64
11CentralKivellPen Set4223.951,005.90
12CentralGillBinder468.99413.54
13CentralKivellBinder5019.99999.50
14CentralJardinePen Set504.99249.50
15CentralGillPencil531.2968.37
16CentralMorganPen Set5512.49686.95
17CentralAndrewsPencil661.99131.34
18CentralSmithPencil671.2986.43
19CentralAndrewsPencil751.99149.25
20CentralGillBinder808.99719.20
21CentralSmithBinder8715.001,305.00
22CentralJardinePencil904.99449.10
23CentralMorganPencil904.99449.10
24CentralJardineBinder9419.991,879.06
25CentralKivellPen Set964.99479.04
26EastJonesBinder44.9919.96
27EastParentPen1519.99299.85
28EastJonesPen Set1615.99255.84
29EastHowardBinder291.9957.71
30EastJonesPencil354.99174.65
31EastJonesBinder604.99299.40
32EastJonesBinder608.99539.40
33EastJonesPen Set624.99309.38
34EastJonesPen648.99575.36
35EastParentPen Set7415.991,183.26
36EastParentBinder8119.991,619.19
37EastJonesPencil951.99189.05
38EastHowardPen964.99479.04
39WestSorvinoDesk3275.00825.00
40WestSorvinoBinder719.99139.93
41WestThompsonPencil321.9963.68
42WestSorvinoPencil562.99167.44
43WestThompsonBinder5719.991,139.43
44WestSorvinoPen761.99151.24
SalesOrders
Cell Formulas
RangeFormula
F2:F44F2=E2*D2
I think my question is either very difficult or easy that no one is able to help. Ok then, just please let me know how to generate unique values like first 3 columns in first table? i.e., region, s# and representative!!??

Thanks in anticipation........
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top