Select LARGE / IF CRITERIAS / WRITE to another worksheet

gldurand

Board Regular
Joined
Jun 8, 2006
Messages
178
Office Version
  1. 2016
Platform
  1. Windows
Hi Experts

I have a challenge that needs some VBA code or complex formula.

Challenge: I want to write certain fields of the 10 largest values from one worksheet to another

Requirements:

I want to search COLUMN BK from "INPUT FILE" for the 10 largest $$ amounts (There could be duplicates)

I want to copy TOP 10 values to another worksheet as long as Column AK is not DUPLICATE.


Output to new worksheet should be the following

COLUMN AK - COLUMN AS - COLUMN A - COLUMN H - COLUMN T- COLUMN BP - COLUMN BK

Confusing.....Work with me please, i really need to figure this out. I would prefer formulas, nut it might not be possible. So VBA code would be welcome and I would use CONTROLS to run them

Please help

Thanks for all your precious time
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I want to copy TOP 10 values to another worksheet as long as Column AK is not DUPLICATE.

Output to new worksheet should be the following

COLUMN AK - COLUMN AS - COLUMN A - COLUMN H - COLUMN T- COLUMN BP - COLUMN BK
Confusing.....

Yes...that is confusing. :)

If you want to find the top 10 values from Column BK without duplicates and list them in Column AK, this would work....

Excel Workbook
AK
1Top 10 Unique
2$3,000
3$2,900
4$2,800
5$2,400
6$2,300
7$2,000
8$1,900
9$1,800
10$1,600
11$1,000
Sheet2
Excel 2007
Cell Formulas
RangeFormula
AK2=LARGE('Input File'!$BK:$BK,1)
AK3=LARGE('Input File'!$BK:$BK,INDEX(FREQUENCY('Input File'!$BK:$BK,AK2-1),2)+1)



Please let me know if I misunderstood what you are trying to do.
 
Upvote 0
Hi JS411

I have the LARGE Function under control. What i am trying to accomplish is to search the source file for the TOP 10 values... That is easy.. Whast you provided helps a little, but I also want to bring with it 7 other fields (in the same row) to another worksheet.

Another issue is that i only want to write those values if a certain field (Column AK) is not duplicate

Any opther help would be greatly aprreciated
 
Upvote 0
OK, here is a sample of my data

Excel Workbook
ABCDEFGHIJK
1Opportunity numberTotal Opportunity ValueProductCustomer nameClient Namesales stageConfidence%close dateOpportunity DescriptionRANK
2XXXXXXX-1$ 1.00AABCG. DurandA1In the Call2501/01/1900aaa10
3XXXXXXX-1$ 1.00BABCM. ReidyA1In the Call2502/01/1900bbb
4XXXXXXX-2$ 2.00AGHIG. DurandB2In the Call5003/01/1900ccc9
5XXXXXXX-2$ 2.00BGHIG. DurandB2Not in the call5004/01/1900ddd
6XXXXXXX-3$ 3.00AMNOM. ReidyC3In the Call2505/01/1900eee
7XXXXXXX-4$ 4.00APQRG. DurandD4In the Call2506/01/1900fff8
8XXXXXXX-5$ 5.00ASTUM. ReidyE5In the Call7507/01/1900ggg
9XXXXXXX-6$ 6.00ASTUG. DurandA1In the Call7508/01/1900hhh7
10XXXXXXX-6$ 6.00BSTUG. DurandA1In the Call7509/01/1900iii
11XXXXXXX-8$ 8.00ABCDG. DurandB2In the Call2511/01/1900kkk6
12XXXXXXX-9$ 9.00AHIJM. ReidyC3Not in the call2512/01/1900lll
13XXXXXXX-10$ 10.00AKLMG. DurandD4In the Call2513/01/1900mmm5
14XXXXXXX-11$ 11.00ANOPG. DurandE5Not in the call2514/01/1900nnn
15XXXXXXX-12$ 12.00ANOPG. DurandE5In the Call2514/01/1900nnn
16XXXXXXX-13$ 13.00ANOPG. DurandA1In the Call2514/01/1900nnn4
17XXXXXXX-14$ 14.00ANOPG. DurandB2In the Call2514/01/1900nnn3
18XXXXXXX-14$ 14.00BNOPG. DurandB2In the Call2514/01/1900nnn
19XXXXXXX-15$ 15.00ANOPG. DurandC3In the Call2514/01/1900nnn2
20XXXXXXX-16$ 16.00ANOPG. DurandD4Not in the call2514/01/1900nnn
21XXXXXXX-17$ 17.00ANOPG. DurandE5In the Call2514/01/1900nnn
22XXXXXXX-18$ 18.00ANOPG. DurandB2In the Call2514/01/1900nnn1
23XXXXXXX-19$ 19.00ANOPM. ReidyA1At risk2514/01/1900nnn
Sheet1



I want to be able to list on another sheet the top 10 of Column B

IF Column A is duplicate only take first occurence
IF Column E = G. Durand
IF Column F = "A1" or "B2" or "C3" or "D4"
IF Column G = "In the Call"

So my result would be the row RANKED Highest to Lowest on another spreadsheet

I hope this clears up my request...

Any assistance would be greatly appreciated by complex formula or VBA Code

Thanks again
 
Upvote 0
Thanks for posting that. It helped clarify a few things, but raised some other questions.

I want to be able to list on another sheet the top 10 of Column B

IF Column A is duplicate only take first occurence
IF Column E = G. Durand
IF Column F = "A1" or "B2" or "C3" or "D4"
IF Column G = "In the Call"

1. I'm confused trying to relate your last post to your OP. Is Column A the same as AK in your OP? Are the other 3 criteria new? How does Column BK relate?

2. Can the values in Column B be duplicated in your results? It's hard to tell because the duplicates align with the duplicates in Col A in your example.

3. What are the seven columns to be copied? There are 11 shown.
 
Upvote 0
Hi JS411

Please forgive me, but we should probably forget the original posting, as i tried to create an example using columns A-B-C-D etc..... I will modify Formulas or VBA code to reflect REAL DATA because my source file is 60 columns wide.

Answers to questions: Is Column A the same as AK in your OP? Are the other 3 criteria new? How does Column BK relate?

Yes column A is the same as AK in my original Post, BK is now Column B in my example... The criteria was always requested, but was more specific

2. Can the values in Column B be duplicated in your results? It's hard to tell because the duplicates align with the duplicates in Col A in your example.
Yes Column B can be duplicates and are always aligned to column A, as these are the same records, but broken out by Product. Ie: Opportunity # (Column A) 2 records that show the same Total Opportunity Value (Column B) because the value is overall but with 2 different Products (Column C)

3. What are the seven columns to be copied? There are 11 shown.

Column A
Column J
Column D
Column F
Column H
Column I
Column B

Thanks for all your assistance

Glenn
 
Upvote 0

Aladin,
Thank you so much for your citation. Your example of using Index & Match with Small is very instructive.

Building on your example, I was able to get so close to solving this, however I'm stumped in trying to incorporate the "IF Column A is duplicate only take first occurence" requirement without the use of a helper column. :banghead:

Here is the best I was able to do...

Excel Workbook
ABCDEFGHIJ
1Top N10TRUE
2Top N Adjusted10FALSE
3IdxOpportunity numberOpportunity DescriptionCustomer namesales stage%close dateTotal Opportunity ValueTRUE
421XXXXXXX-18nnnNOPB22514/01/1900$ 18.00FALSE
518XXXXXXX-15nnnNOPC32514/01/1900$ 15.00TRUE
616XXXXXXX-14nnnNOPB22514/01/1900$ 14.00TRUE
715XXXXXXX-13nnnNOPA12514/01/1900$ 13.00TRUE
812XXXXXXX-10mmmKLMD42513/01/1900$ 10.00TRUE
910XXXXXXX-8kkkBCDB2251/11/1900$ 8.00FALSE
108XXXXXXX-6hhhSTUA1751/8/1900$ 6.00TRUE
116XXXXXXX-4fffPQRD4251/6/1900$ 4.00TRUE
123XXXXXXX-2cccGHIB2501/3/1900$ 2.00TRUE
131XXXXXXX-1aaaABCA1251/1/1900$ 1.00TRUE
14TRUE
15TRUE
16TRUE
17FALSE
18TRUE
19TRUE
20TRUE
21TRUE
22TRUE
Sheet1
Excel 2007
Cell Formulas
RangeFormula
B2=COUNTIF(Sheet2!B2:B23,"<="&SMALL(Sheet2!B2:B23,B1))
B4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(B$3,Sheet2!$A$1:$K$1,0)),"")
C4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(C$3,Sheet2!$A$1:$K$1,0)),"")
D4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(D$3,Sheet2!$A$1:$K$1,0)),"")
E4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(E$3,Sheet2!$A$1:$K$1,0)),"")
F4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(F$3,Sheet2!$A$1:$K$1,0)),"")
G4=IF(N($A4),INDEX(Sheet2!$A$2:$K$23,$A4,MATCH(G$3,Sheet2!$A$1:$K$1,0)),"")
J1=ISNA(MATCH(Sheet2!A2,Sheet2!A$1:A1,0))
#VALUE!
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}. Note: Do not try and enter these manually yourself
I've tried variations of the CSE formula below for H4, but I haven't found a way to get that first expression to evaluate to the equivalent of Range in Column J.

Code:
{=LARGE(ISNA(MATCH(Sheet2!A$2:A$23,Sheet2!A$1:A1,0))*
(Sheet2!E$2:E$23="G. Durand")*(Sheet2!F$2:F$23={"A1","B2","C3","D4"})
*(Sheet2!G$2:G$23="In the Call")*Sheet2!B$2:B$23,ROWS($H$4:H4))}

Any help would be greatly appreciated :)

Glen, Hope this helps!
 
Last edited:
Upvote 0
Hi Jerry

I dont mind the helper column, it works great in my mock up example... :( when i convert it into my real data i am getting a #N/A as a result in Cell H4....


I checked all the values and each formula character by character and everything seems to be ok.

I have prepared my actual SOURCE file of my real data with existing rows and titles..
Is there any way possible I can maybe forward you the spreadsheet and you can check out my formulas in the "Live" version.

It would expedite things, and i have a deadline fast approaching...

Send me an address so I may send you a gift certificate for STARBUCKS or something....:)

Thanks so much
 
Upvote 0
Glen,

I'm glad to hear this helped. If you are going to keep a helper column, You might want to locate it on the same sheet as the source data since there is one cell per row. I just cut and paste this data into the report sheet so it would show up on a single screen shot.

I could take a look at your file, but I won't be able to get to that until tonight. I'll send you a PM with my email.

Thanks for offering to send a gift, but this is an all-volunteer board so I can't accept that. Your appreciation is more than enough thanks. :)
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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