Advanced filters & VBA code

John_Gil

New Member
Joined
Jun 3, 2020
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone! :)

I need to develop a macro that sums cases and packs (units) quantities from an exported file. The final document has the below aspect:

CasesUnits
WeekCases dispatchedCases forecastedCases orderedUnits despatchedUnits forecastedUnits ordered
35751777947892118785125137124681
Group A268027402746462724714947256
Group B274529203046450934866449939
Group C619695619109141223810914
Group D631566639597651866042
Group E167147167200417602004
Group F000000
Group G6757266758526101418526

Well each one of the groups have specific products associated what means that has to have specific filters from the exported file:
Group A - Filtered by "BACON" on column species and "OCADO" on column Sub-ProductTier;
Group B- Filtered by "Eden" on column Sub-ProductTier;
Group C- Filtered by "Organic" on column Sub-ProductTier;
Group D- Filtered by "PORK" on column species and "OCADO" on column Sub-ProductTier;
Group E- Filtered by "BACON" on column species;
Group F- Filtered by product code (RTO004, RTO005, RTO065, RTO008, RTO011,RTO012, RTO013);
Group G- Filtered by "LAMB" on column species and "OCADO" on column Sub-ProductTier;

The file from where this information needs to be taken has the below format:
ProductProductAreaCategorySpeciesSub-ProductTierProductTierCustomerFactTypeUnit
12/07/2020​
RTO140BURGERSFRESHBEEFOCADOCOREOCADO[Live] Combined HFI Forecast with PLM'sB
0​
RTO138SAUSAGEBREAKFASTPORKTESCO BRANDCOREOCADO[Live] Combined HFI Forecast with PLM'sB
0​
RTO137BURGERSFRESHBACONORGANICPREMIUMOCADO[Live] Combined HFI Forecast with PLM'sB
83​
RTO135JOINTFRESHLAMBEDENBRANDOCADO[Live] Combined HFI Forecast with PLM'sB
1​

The macro should first filter and then sum the cases and trays and present them into the first table.

Could you please help me with this guys? I'm just really starting to work with VBA and I would really appreciate your work.

Thank you,
John
 
Hi Peter! :)

Apologies for the late reply but I had a very busy day yesterday! I thought about slicers as well but could this be done automatically or is something that needs to be changed manually every time that a file is exported?

Thanks,
John
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi John,

Having played more with your data I'm almost conceding defeat on the complex filtering - I still feel something is possible, but it seems just beyond my skills! If we really need that sort of a solution I'll try and get someone else interested who's knowledge of Powerquery is somewhat more than mine.

However, getting back to the data, pivot tables and slicers. The spreadsheet here: 'JGill Challenge' uses slicers to filter your data - it should be intuitive simply click the choices you wish to see (CTRL Click to select multiple choices). If an option appears 'greyed' out then it is not available given the other filters that have been set. Whenever new data is imported then your choices will be updated automatically.

Let me know how you get on.
 
Upvote 0
Thank you for your time and patience Peter really appreciate it! I'm watching videos to learn how to advance with is! :)

I will let you know!

Cheers,
John
 
Upvote 0
some thing I didn't mention is the ability to change the grouping order. When you open the spreadsheet you should see the Field selection table on the right if the screen. At bottom left of that is the rows section. Simply click and drag them too whatever order you want. Should you inadvertently remove one you can add it back by dragging from the field lusty at the top of that pane.

I'm still thinking about how to implement a filter on Product - I have an idea that I need to test!!

HTH
 
Upvote 0
Hi John,

I've updated the file at the link above. It now provides the ability to filter more easily by product code. When you open the file you'll see a small table on the right hand side called Product Filter, any product codes you enter there will be selected when you choose 'Filtered' in the slicer above the table. You should also see the selected product codes appear in the 'Products' slicer (this isn't me being clever its just how Excel works). If you choose 'Unfiltered' you'll get all the product codes that aren't listed in table. To clear the filter either click both Filtered and Unfiltered or click the clear filter button at top right of the slicer.

HTH
 
Upvote 0
Hi John,

Updated the file again - there's now two pivot tables. The first report you should see will have the data grouped as you'd asked for - its quite hard to change. The second report is the slicer based report I discussed in the previous post.
 
Upvote 0
Hi Peter,

Once again thank you for you support! I will try it tomorrow and let you know how it runs.

Regards,
John
 
Upvote 0
Hi Peter! I thinks the two pivot tables and the slicers are doing a good job! My question is where is the data stored? Can't find it on any of the tabs...

Thank you,
John
 
Upvote 0
HI John,

You won't see the data on any of the tabs as I've chosen to only keep it internal to excel (its in the 'Data Model'). However, I also realise that that is pretty useless for you! This link is a macro version of the spreadsheet. If you go to the 'Settings' tab, you'll see a button at the top with 'Get File Name', if you click that you should then see a fileopen dialog where you can choose your source data. It will access that file and then autorefresh the pivottables. If you do need to see the data then click on the Data Ribbon, Show Queries option on the 'Get & Transform' tab. You should then see a list of 3 queries on the righthand side. Right Click on the top one (should have about 10000 entries) and choose 'Load to..', in the dialog box that appears click the radio button next to 'Table' which will deselect 'Only Create Connnection'. You will then get a new sheet with the data showing - this is not the raw data, but is the processed data which allows the creation of the pivottables.


HTH
 
Upvote 0
Hi Peter,

You were right is very difficult to implement a clear procedure for this. I was thinking yo keep the power query which is working perfectly but instead of the pivot table and slicer to use the sumifs function. What do you think? I tried it and it looks to be working!! :eek:

Regards,
John
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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