Macro to built final file from 3 different files

Status
Not open for further replies.

Cris_93

New Member
Joined
Nov 1, 2019
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
Hello Excel masters :smile:

I need your help in order to develop a final file (CustomerForecast) from 3 different files with some restrictions.

The final file should have the below format. The columns "FactType" and "Unit" should have always the same values.


[TABLE="class: cms_table, width: 0"]
<tbody>[TR]
[TD]Depot/StoreFormat[/TD]
[TD]Product[/TD]
[TD]FactType[/TD]
[TD]Unit[/TD]
[TD]Date[/TD]
[TD]Value[/TD]
[/TR]
[TR]
[TD]Dublin[/TD]
[TD]RTP088[/TD]
[TD]Customer Forecast[/TD]
[TD]Cases[/TD]
[TD]02/11/2019[/TD]
[TD]23[/TD]
[/TR]
[TR]
[TD]Belfast[/TD]
[TD]RTB222[/TD]
[TD]Customer Forecast[/TD]
[TD]Cases[/TD]
[TD]12/11/2019[/TD]
[TD]32[/TD]
[/TR]
[TR]
[TD]Hatfield[/TD]
[TD]RTP088[/TD]
[TD]Customer Forecast[/TD]
[TD]Cases[/TD]
[TD]07/11/2019[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]Dordon[/TD]
[TD]RTL008[/TD]
[TD]Customer Forecast[/TD]
[TD]Cases[/TD]
[TD]05/11/2019[/TD]
[TD]30[/TD]
[/TR]
[TR]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[/TR]
</tbody>[/TABLE]


The other data for the others 4 columns come from the below 3 different files. I will put in red the required columns from each file:

"ROI.csv"

[TABLE="class: cms_table, width: 1541"]
<tbody>[TR]
[TD="align: center"]Supplier number[/TD]
[TD="align: center"]Category area[/TD]
[TD="align: center"]Star line[/TD]
[TD="align: center"]Tpnb[/TD]
[TD="align: center"]Description[/TD]
[TD="align: center"]Tpnd[/TD]
[TD="align: center"]Case size[/TD]
[TD="align: center"]Occ[/TD]
[TD="align: center"]Depot number[/TD]
[TD="align: center"]Depot name[/TD]
[TD="align: center"]Forecast date[/TD]
[TD="align: center"]Order date[/TD]
[TD="align: center"]Delivery date[/TD]
[TD="align: center"]Forecast cases[/TD]
[/TR]
[TR]
[TD="align: center"]5997500[/TD]
[TD="align: center"]MFP[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]52440995[/TD]
[TD="align: center"]PORK MINCE 500G[/TD]
[TD="align: center"]31411873[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]5.05E+12[/TD]
[TD="align: center"]735[/TD]
[TD="align: center"]BALLYMUN FRESH PBL[/TD]
[TD="align: center"]03/10/2019[/TD]
[TD="align: center"]04/10/2019[/TD]
[TD="align: center"]05/10/2019[/TD]
[TD="align: center"]40[/TD]
[/TR]
[TR]
[TD="align: center"]5997500[/TD]
[TD="align: center"]MFP[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]52445008[/TD]
[TD="align: center"]IRISH LAMB MINCE 15% FAT 533G[/TD]
[TD="align: center"]37216980[/TD]
[TD="align: center"]4[/TD]
[TD="align: center"]5.06E+12[/TD]
[TD="align: center"]735[/TD]
[TD="align: center"]BALLYMUN FRESH PBL[/TD]
[TD="align: center"]03/10/2019[/TD]
[TD="align: center"]04/10/2019[/TD]
[TD="align: center"]07/10/2019[/TD]
[TD="align: center"]10[/TD]
[/TR]
[TR]
[TD="align: center"]5997500[/TD]
[TD="align: center"]MFP[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]52483552[/TD]
[TD="align: center"]T. ROUND STEAK BEEF MINCE 10% FAT 554G[/TD]
[TD="align: center"]34945576[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]5.06E+12[/TD]
[TD="align: center"]735[/TD]
[TD="align: center"]BALLYMUN FRESH PBL[/TD]
[TD="align: center"]03/10/2019[/TD]
[TD="align: center"]16/10/2019[/TD]
[TD="align: center"]17/10/2019[/TD]
[TD="align: center"]102[/TD]
[/TR]
[TR]
[TD="align: center"]5997500[/TD]
[TD="align: center"]MFP[/TD]
[TD="align: center"]N[/TD]
[TD="align: center"]63755738[/TD]
[TD="align: center"]T. FIN* IRISH CANADIAN MAPLE RASHERS 240G[/TD]
[TD="align: center"]32607750[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]5.06E+12[/TD]
[TD="align: center"]735[/TD]
[TD="align: center"]BALLYMUN FRESH PBL[/TD]
[TD="align: center"]03/10/2019[/TD]
[TD="align: center"]21/10/2019[/TD]
[TD="align: center"]22/10/2019[/TD]
[TD="align: center"]48[/TD]
[/TR]
[TR]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[TD="align: center"]…[/TD]
[/TR]
</tbody>[/TABLE]


The Depot name "BALLYMUN FRESH PBL" should be picked as "Dublin" to the final file;

"NI.xls"

[TABLE="class: cms_table, width: 0"]
<tbody>[TR]
[TD]Supplier number[/TD]
[TD]Occ[/TD]
[TD]Tpnd[/TD]
[TD]Description[/TD]
[TD]Depot number[/TD]
[TD]Depot name[/TD]
[TD]Case size[/TD]
[TD]Forecast date[/TD]
[TD]Order date[/TD]
[TD]Delivery date
[/TD]
[TD]Forecast cases[/TD]
[/TR]
[TR]
[TD]6242200[/TD]
[TD]2.0955E+11[/TD]
[TD]28798712[/TD]
[TD]T.FIN 1 BEEF RIBEYE STEAK[/TD]
[TD]835[/TD]
[TD]NI BELFAST FRESH PBL[/TD]
[TD]12[/TD]
[TD]03/10/2019[/TD]
[TD]19/10/2019
[/TD]
[TD]21/10/2019
[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]6242200[/TD]
[TD]2.0955E+11[/TD]
[TD]28798712[/TD]
[TD]T.FIN 1 BEEF RIBEYE STEAK[/TD]
[TD]835[/TD]
[TD]NI BELFAST FRESH PBL[/TD]
[TD]12[/TD]
[TD]03/10/2019[/TD]
[TD]10/10/2019
[/TD]
[TD]11/10/2019
[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]6242200[/TD]
[TD]2.0955E+11[/TD]
[TD]28798712[/TD]
[TD]T.FIN 1 BEEF RIBEYE STEAK[/TD]
[TD]835
[/TD]
[TD]NI BELFAST FRESH PBL[/TD]
[TD]12[/TD]
[TD]03/10/2019[/TD]
[TD]05/10/2019[/TD]
[TD]07/10/2019
[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]6242200[/TD]
[TD]2.0955E+11[/TD]
[TD]28798712[/TD]
[TD]T.FIN 1 BEEF RIBEYE STEAK[/TD]
[TD]835[/TD]
[TD]NI BELFAST FRESH PBL[/TD]
[TD]12[/TD]
[TD]03/10/2019[/TD]
[TD]09/10/2019[/TD]
[TD]10/10/2019
[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]...[/TD]
[/TR]
</tbody>[/TABLE]

The Depot name "NI BELFAST FRESH PBL" should be picked as "Belfast" to the final file;

"Ocado.xls"

[TABLE="class: cms_table, width: 0"]
<tbody>[TR]
[TD]Forecast Delivery Date
[/TD]
[TD]Delivery Place[/TD]
[TD]Order Group[/TD]
[TD]SKU
[/TD]
[TD]Supplier Line Number[/TD]
[TD]Product Description[/TD]
[TD]Case Barcode
[/TD]
[TD]Forecast Order Qty (Cases)[/TD]
[/TR]
[TR]
[TD]06 October 2019 05:00:00
[/TD]
[TD]Dordon[/TD]
[TD]Do: HFS[/TD]
[TD]77760011[/TD]
[TD]77760011[/TD]
[TD]Ocado Lean Beef Steak Mince 5% Fat (500 GR)[/TD]
[TD]15055004195[/TD]
[TD]60[/TD]
[/TR]
[TR]
[TD]06 October 2019 05:00:00
[/TD]
[TD]Dordon[/TD]
[TD]Do: HFS[/TD]
[TD]296274011[/TD]
[TD]296274011[/TD]
[TD]Eden Beef Steak Mince 15% Fat (500 GR)[/TD]
[TD]05391810242[/TD]
[TD]38[/TD]
[/TR]
[TR]
[TD]06 October 2019 08:30:00
[/TD]
[TD]Hatfield[/TD]
[TD]Ha: HFS[/TD]
[TD]435984011[/TD]
[TD]435984011[/TD]
[TD]Eden Lean Beef Steak Mince 5% Fat (400 GR)[/TD]
[TD]05391811102[/TD]
[TD]51[/TD]
[/TR]
[TR]
[TD]07 October 2019 08:00:00
[/TD]
[TD]Erith CFC[/TD]
[TD]Er: HFS[/TD]
[TD]72581011[/TD]
[TD]72581011[/TD]
[TD]Ocado 4 Quarter Pounder Beef Burgers (454 GR)[/TD]
[TD]15055002382[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]07 October 2019 08:00:00
[/TD]
[TD]Erith CFC[/TD]
[TD]Er: HFS[/TD]
[TD]402166011[/TD]
[TD]402166011[/TD]
[TD]Eden Aberdeen Angus Beef Roasting Joint (1.5 KG)[/TD]
[TD]95391811068[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[TD]…[/TD]
[/TR]
</tbody>[/TABLE]


As you for sure noticed the "Product" on the final file has a different format/id than in the three files "Tpnd" and "SKU". That's because for each product from our costumers we use a specific internal code (Retail code). The match between our suppliers code and our RT codes is made in a different file called "Week Forecast" and has the bellow aspect.


[TABLE="class: cms_table, width: 0"]
<tbody>[TR]
[TD]TPND[/TD]
[TD]Code[/TD]
[TD]Description[/TD]
[/TR]
[TR]
[TD]22918725[/TD]
[TD]RPP001[/TD]
[TD]T GAMMON STKS WT CARMELISED ONION MPQAS[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP001CP[/TD]
[TD]TESCO GAMMON STEAK WITH CARMELISED CP[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP001WP[/TD]
[TD]WIP TESCO GAMMON STEAK WITH CARMELISED[/TD]
[/TR]
[TR]
[TD]22918656[/TD]
[TD]RPP002[/TD]
[TD]TESCO BACON CHOPS WT MSTRD BUTTER MPQAS[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP002CP[/TD]
[TD]TESCO BACON CHOPS WITH MUSTARD BUTTR CP[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP002WP[/TD]
[TD]WIP TESCO BACON CHOPS WITH MUSTARD BUTTR[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP003[/TD]
[TD]MARKET VALUE PALE BACK BACON JOINT[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP003WP[/TD]
[TD]WIP MARKET VALUE PALE BACK BACON JOINT[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP004[/TD]
[TD]MARKET VALUE PALE HAM FILLET[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP004WP[/TD]
[TD]WIP MARKET VALUE PALE HAM FILLET[/TD]
[/TR]
[TR]
[TD]23966061[/TD]
[TD]RPP005[/TD]
[TD]TESCO THICK CUT SMKD RASHERS 250G MPQAS[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP005WP[/TD]
[TD]WIP SMOKED THICKCUT BACK BACON RASHERS[/TD]
[/TR]
[TR]
[TD]23966147[/TD]
[TD]RPP006[/TD]
[TD]TESCO THICKCUT MAPLE RASHERS 250G MPQAS[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]RPP006WP[/TD]
[TD]WIP THICKCUT MAPLE BACK BACON RASHERS[/TD]
[/TR]
</tbody>[/TABLE]


Some of the codes are inactive. The only active code is the one in front of the Tpnd code. The macro should match the code from the supplier and pick the correspondent Retail Code to the final file.

Thanks a lot guys!

Kind regards,
Cristian
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Duplicate https://www.mrexcel.com/forum/excel...a-3-files-create-final-file-restrictions.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

Note that sometimes posts from new users require Moderator approval before you can see them on the public forums. When this happens, you should see a message to that effect when you try to post it.
Please be patient and do not attempt to post the question again.

 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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