XLOOKUP multiple items from one column, returning CHOOSECOLS

Vcoppens

Board Regular
Joined
Apr 16, 2012
Messages
96
Office Version
  1. 365
Platform
  1. Windows
Hi,

From about 30000 rows and 50 columns, I need to extract data based on multiple numbers from one particular column, called TYPE.

There are about 20 different types, and I only need to extract types 1 - 3 - 5 and 7.

My formula works perfectly well when I look up, for example, number 1.

=xlookup(A1,F:F,choosecols(A:BD,1,5,2,20,27,17,21,34,19)

However, when I lookup the array with TYPE numbers from 1 through 7, I get a #SPILL! error.

Lookup the array of numbers in column F.

1
3
5
7

The result would return a compacted table:

NumberNameAmountOriginal AmountDatePercentage

If anyone has a suggestion, I would greatly appreciate it.

Thank you!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Spill usually means there is data already in the cells the array is trying to write to

What version of excel are you using - would be worth updating your profile to show version as solutions will be dependant on what version you have and therefore what functions available

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

This will possibly enable a quicker and more accurate solution for you.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC

then put the sample spreadsheet onto a share

I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed

Make sure you set any share or google to share to everyone
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Xlookup will only return an array in one direction, so if you try to lookup A1:A4 you will only get the values from col A
 
Upvote 0
Do you mean something like this:
Excel Formula:
=FILTER(CHOOSECOLS(A:BD,1,5,2,20,27,17,21,34,19)),ISNUMBER(MATCH(F:F,{1,3,5,7},0)),"")
 
Upvote 0
Book2
ABCDEFGHIJKLMNOPQRSTUVW
1Hdr1Hdr2Hdr5TYPEHdr7Hdr8Hdr9Hdr10Hdr11Hdr12Hdr1Hdr2Hdr5TYPEHdr7Hdr8Hdr9Hdr10Hdr11Hdr12
2a1b1e11g1h1i1j1k1l1h1a1b1e11g1h1i1j1k1l1
3a2b2e26g2h2i2j2k2l2a4b4e43g4h1i4j4k4l4
4a3b3e32g3h3i3j3k3l31a6b6e65g6h1i6j6k6l6
5a4b4e43g4h1i4j4k4l45a10b10e107g10h1i10j10k10l10
6a5b5e59g5h1i5j5k5l53a12b12e123g12h1i12j12k12l12
7a6b6e65g6h1i6j6k6l67
8a7b7e75g7h7i7j7k7l7
9a8b8e87g8h8i8j8k8l8
10a9b9e98g9h1i9j9k9l9
11a10b10e107g10h1i10j10k10l10
12a11b11e111g11h11i11j11k11l11
13a12b12e123g12h1i12j12k12l12
14a13b13e135g13h13i13j13k13l13
15
16N1=A1:J1
17N2=FILTER(A2:J14,(F2:F14=L2)*(COUNTIF(L4:L7,D2:D14)>0))
Sheet1
 
Upvote 0
Spill usually means there is data already in the cells the array is trying to write to

What version of excel are you using - would be worth updating your profile to show version as solutions will be dependant on what version you have and therefore what functions available

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

This will possibly enable a quicker and more accurate solution for you.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC

then put the sample spreadsheet onto a share

I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed

Make sure you set any share or google to share to everyone

Thank you for the steps on create the XL2BB addin. I have been trying for a few hours to make this work but it states that I cannot open the file in the protected view. I have teh suggestion from Mr. Pelleiter without success. I have created a simplified sheet showing the raw data, the 2 different formulas and their result and the desired result.
 

Attachments

  • xlookup choosecols.png
    xlookup choosecols.png
    39.2 KB · Views: 3
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Xlookup will only return an array in one direction, so if you try to lookup A1:A4 you will only get the values from col A
Thank you for the suggestion - I have updated my Excel version.
You are correct, looking up A1:A4 only provides the information from col A instead of the requested columns.
 
Upvote 0
Do you mean something like this:
Excel Formula:
=FILTER(CHOOSECOLS(A:BD,1,5,2,20,27,17,21,34,19)),ISNUMBER(MATCH(F:F,{1,3,5,7},0)),"")

Thank you - I tried to implement this formula, but it states that I have entered too few arguments. Generally, it indicates where the issue might be. I have attached a simplified picture to my post as I am unable to download xl2bb. I am not sure if that would help you. I think you might be on the right direction.
 
Upvote 0
Book2
ABCDEFGHIJKLMNOPQRSTUVW
1Hdr1Hdr2Hdr5TYPEHdr7Hdr8Hdr9Hdr10Hdr11Hdr12Hdr1Hdr2Hdr5TYPEHdr7Hdr8Hdr9Hdr10Hdr11Hdr12
2a1b1e11g1h1i1j1k1l1h1a1b1e11g1h1i1j1k1l1
3a2b2e26g2h2i2j2k2l2a4b4e43g4h1i4j4k4l4
4a3b3e32g3h3i3j3k3l31a6b6e65g6h1i6j6k6l6
5a4b4e43g4h1i4j4k4l45a10b10e107g10h1i10j10k10l10
6a5b5e59g5h1i5j5k5l53a12b12e123g12h1i12j12k12l12
7a6b6e65g6h1i6j6k6l67
8a7b7e75g7h7i7j7k7l7
9a8b8e87g8h8i8j8k8l8
10a9b9e98g9h1i9j9k9l9
11a10b10e107g10h1i10j10k10l10
12a11b11e111g11h11i11j11k11l11
13a12b12e123g12h1i12j12k12l12
14a13b13e135g13h13i13j13k13l13
15
16N1=A1:J1
17N2=FILTER(A2:J14,(F2:F14=L2)*(COUNTIF(L4:L7,D2:D14)>0))
Sheet1
Thank you for the formula, this seems to works but I have about 50 columns and would only need about 8 of these columns ....
 
Upvote 0

Forum statistics

Threads
1,225,317
Messages
6,184,250
Members
453,223
Latest member
Ignition04

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