I've got almost 70K lines of exported non table friendly data to sort out

hardend

New Member
Joined
Feb 3, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi!

So we needed to export about 750 customers data into another system. About 67k rows in total
There are about 9 columns and 60-90 rows for each customer, depending on how much data we have for each customer.
Customer number
835Company A...
Some road...phone035-123456
some town...phone 2070-354786
...Fax:020-159632
..................
Referens:sam smith...
VAT-nr:3265-6363...Alternative:Data 1
..................
Transporter:DHL...
..................
256Some other Company...
..................
512Company B...
The only data i actually needed to extract for each customer is the Customer number, Company name, Transporter and Alternative

I've been messing around with vba crashing excel and failing to excecute as I want, for a couple of days now trying to get the data into a table looking like this:
835Company ADHLData 1
256Some other CompanyDB SchenkerData 2
512Company BDHLData 3

Since I'm not sure what to search for google is not helping much.

How would you approach it?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Hardend,

I note your data doesn't support the example solution but I guess that's just an omission.

I would add a column (A) to repeat the Customer Number so I had a lookup for the Transporter and Alternative, then I'd build the result table using AGGREGATE (columns I to L).

Hardend.xlsx
ABCDEFGHIJKL
1Customer numberCustomer numberCustomer numberCompany NameTransporterAlternative
2835835Company A...835Company ADHLData 1
3835Some road...phone035-123456256Some other Company  
4835some town...phone 2070-354786512Company B  
5835...Fax:020-159632    
6835..................    
7835Referens:sam smith...    
8835VAT-nr:3265-6363...Alternative:Data 1    
9835..................    
10835Transporter:DHL...    
11835..................    
12256256Some other Company...    
13256..................    
14512512Company B...    
Sheet1
Cell Formulas
RangeFormula
I2:I14I2=IFERROR(INDEX($A$2:$A$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
J2:J14J2=IFERROR(INDEX($C$2:$C$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
K2:K14K2=IFERROR(INDEX($D$2:$D$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($C$2:$C$99999="Transporter:")),ROW()-ROW($I$1))),"")
L2:L14L2=IFERROR(INDEX($G$2:$G$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($F$2:$F$99999="Alternative:")),ROW()-ROW($I$1))),"")
A2:A14A2=IF(ISNUMBER(B2),B2,N(A1))
 
Upvote 0
Hi Hardend,

I note your data doesn't support the example solution but I guess that's just an omission.

I would add a column (A) to repeat the Customer Number so I had a lookup for the Transporter and Alternative, then I'd build the result table using AGGREGATE (columns I to L).

Hardend.xlsx
ABCDEFGHIJKL
1Customer numberCustomer numberCustomer numberCompany NameTransporterAlternative
2835835Company A...835Company ADHLData 1
3835Some road...phone035-123456256Some other Company  
4835some town...phone 2070-354786512Company B  
5835...Fax:020-159632    
6835..................    
7835Referens:sam smith...    
8835VAT-nr:3265-6363...Alternative:Data 1    
9835..................    
10835Transporter:DHL...    
11835..................    
12256256Some other Company...    
13256..................    
14512512Company B...    
Sheet1
Cell Formulas
RangeFormula
I2:I14I2=IFERROR(INDEX($A$2:$A$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
J2:J14J2=IFERROR(INDEX($C$2:$C$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
K2:K14K2=IFERROR(INDEX($D$2:$D$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($C$2:$C$99999="Transporter:")),ROW()-ROW($I$1))),"")
L2:L14L2=IFERROR(INDEX($G$2:$G$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($F$2:$F$99999="Alternative:")),ROW()-ROW($I$1))),"")
A2:A14A2=IF(ISNUMBER(B2),B2,N(A1))
Thanks Toadstool for the quick reply!

Now my table looks just as yours.
I'm really impressed by your skills!

But I'm not able to get the formula to work in K3:K9999 and L3:L9999
It works for K2 and L2 tough.

In not familiar with the aggregate function at all and have been the googleing without anything to show for it.
Do you have any idea why it doesn't continue?
 
Upvote 0
My mistake. I only need the 1st match of Customer Number and Transporter:/Alternative: so change the K2 & L2 down formulae as below.

Hardend.xlsx
ABCDEFGHIJKL
1Customer numberCustomer numberCustomer numberCompany NameTransporterAlternative
2835835Company A...835Company ADHLData 1
3835Some road...phone035-123456256Some other CompanyDB SchenkerData 2
4835some town...phone 2070-354786512Company BDHLData 3
5835...Fax:020-159632    
6835..................    
7835Referens:sam smith...    
8835VAT-nr:3265-6363...Alternative:Data 1    
9835..................    
10835Transporter:DHL...    
11835..................    
12256256Some other Company...    
13256...Transporter:DB Schenker...Alternative:Data 2    
14512512Company B...    
15512
16512Transporter:DHL
17512Alternative:Data 3
Sheet1
Cell Formulas
RangeFormula
I2:I14I2=IFERROR(INDEX($A$2:$A$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
J2:J14J2=IFERROR(INDEX($C$2:$C$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
K2:K14K2=IFERROR(INDEX($D$2:$D$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($C$2:$C$99999="Transporter:")),1)),"")
L2:L14L2=IFERROR(INDEX($G$2:$G$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($F$2:$F$99999="Alternative:")),1)),"")
A2:A17A2=IF(ISNUMBER(B2),B2,N(A1))
 
Upvote 0
Solution
My mistake. I only need the 1st match of Customer Number and Transporter:/Alternative: so change the K2 & L2 down formulae as below.

Hardend.xlsx
ABCDEFGHIJKL
1Customer numberCustomer numberCustomer numberCompany NameTransporterAlternative
2835835Company A...835Company ADHLData 1
3835Some road...phone035-123456256Some other CompanyDB SchenkerData 2
4835some town...phone 2070-354786512Company BDHLData 3
5835...Fax:020-159632    
6835..................    
7835Referens:sam smith...    
8835VAT-nr:3265-6363...Alternative:Data 1    
9835..................    
10835Transporter:DHL...    
11835..................    
12256256Some other Company...    
13256...Transporter:DB Schenker...Alternative:Data 2    
14512512Company B...    
15512
16512Transporter:DHL
17512Alternative:Data 3
Sheet1
Cell Formulas
RangeFormula
I2:I14I2=IFERROR(INDEX($A$2:$A$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
J2:J14J2=IFERROR(INDEX($C$2:$C$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(ISNUMBER($B$2:$B$99999)),ROW()-ROW($I$1))),"")
K2:K14K2=IFERROR(INDEX($D$2:$D$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($C$2:$C$99999="Transporter:")),1)),"")
L2:L14L2=IFERROR(INDEX($G$2:$G$99999,AGGREGATE(15,6,ROW($B$2:$B$99999)-ROW($B$1)/(($A$2:$A$99999=$I2)*($F$2:$F$99999="Alternative:")),1)),"")
A2:A17A2=IF(ISNUMBER(B2),B2,N(A1))
You are wonderful Toadstool!!!!

That did it!
Thank you so much!!!
 
Upvote 0
You're welcome.

Quick explanation...

If you type =AGGREGATE( you'll see a whole bunch of options. I'm using 15 for the SMALL function. I'm then using 6 to tell it to ignore internal errors. Normally the array will be a range of cells and it will give me the kth SMALLest value from that list, but I'm using ROW numbers (and then subtracting whatever the header row is to get the correct offset). This means it will go through rows 2 to 99999.
INTERESTING NOTE: It just uses the row numbers so instead of ROW($B$2:$B$99999)-ROW($B$1) I could use ROW($zz$2:$zz$99999)-ROW($zz$1) and it would still work fine.

As AGGREGATE goes through each ROW number I divide it by (ISNUMBER($B$2:$B$99999)). If it is not a number then I get a logical zero (FALSE) and dividing that into the row number gives #DIV/0 which the 6 option tells it to ignore. If it IS a NUMBER I get logical 1 (TRUE) which divided into that row gives the row number, which INDEX then uses to return the Customer Number.

Next is the k parameter ROW()-ROW($I$1) so that adds to the SMALL function search so I2 is looking for the 1st numeric in column B but I3 will look for the 2nd numeric, and return 256.

The Company Name is basically the same but for Transporter and Alternative I only want to find the first entry where the Company Number in the new column (so always contains the current/last Company Number in column A) matches that in column I and Transporter: is in column C, Alternative: is in column F.
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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