Using Excel to to Return unique values for Identical lookup values - vba

I am attempting to use VLookup to match a "Purchase Number" to a specific "Invoice Number". To accomplish this, I have several identifiers about the purchase that I put together to come up with a special "Concat ID". I then have a list of Invoice Numbers that also has the same list of identifiers to create the same "Concat ID'.
The problem I am running into is that the set of identifiers is not unique (aka a purchase of 10 Computers might happen multiple times a year, therefore it is in my list multiple times). Because of this, when I use Vlookup to match the 2 IDs, it always is giving me the same Purchase Number for each time the Concat ID is found (which is just the first occurrence of that Concat ID).
Since there is no other data that would allow for matching (because Invoice date and purchase date are not always the same date or even close to one another), I am just wanting to ensure that each Invoice Number has a unique purchase number.
I'm not sure if its possible, but I was hoping I would be able to perform the vlookup then just skip to the next time the Concat ID is found, allowing for no duplicates, but that hasn't been feasible for me. Because this is a file of 16000 rows, any insight is very appreciated.
I'm sure that's not the clearest explanation, so I've attached a screenshot of the 2 examples in case anyone has any insight. I've been using a simple VLookup, but I'm open to trying VBA or any other suggestions everyone has. As always, thank you Stack community in advance for any help/insight!
Purchase Info
Attempted Matchup with Invoice Info

I'm still not sure what you expect to do with the ConcatID purchase number, but to return the purchase numbers that match your specific ConcatID, generated in the manner you describe in your question, and "skipping to the next" in the case of identical ConcatID's, you can do something like the following;
Note that I made a Table out of your original data, and am using structured references. This allows a much smaller amount of data to be processed compared with referencing the entire column, and will also autoadjust the range as you add/remove rows
Also note that if your Table starts in other than Row 1, you will need to make an adjustment in the formula to account for that.
G2: =INDEX(PurchaseTbl[#All],AGGREGATE(15,6,1/1/(PurchaseTbl[Concat ID]=F2)*ROW(PurchaseTbl),COUNTIF($F$1:F2,F2)),7)
and fill down as far as needed

I've got a really dorky solution, but maybe it will help.
Use this formula to create a unique ID for each row. It will count how many times the specific Concat ID has been used previously in the table, then append it to the end. You can use the Concat ID Unique in your VLookup to get the correct Purchase Number.
=D2 & "_" & (COUNTIF(D$1:D1, "=" & D2))

Related

Inserting a blank line for a certain amount of columns only and aligning two sets of columns with diff amounts of row data correctly

Hi Everyone I am hoping someone to help me, it seems like a complicated one to me so lets see:
I have to compare two amounts of information for errors line by line for price differences. The excel document is 15000 rows long so hence why I need a macro! Columns A to I hold the the first document information, then K to Q has the second amount of document info. The comparison needs to happen between Column A and Q which have matching "shipper"numbers. Each shipper number has a certain number of part numbers below it which each contain the info I need to compare. The problem is one shipper may have more or less parts on document one compared to document two so I cant just run a insert line using vba as it will cut document 2 incorrect. Is it possbile 1.) insert a line after each shipper changes in document one by looking at column A (Shipper no) and running it until Col I and at the same time (or after) inserting a blank line for documents two looking at column Q AND is it possible to try match up each shipper so they start on the same line to compare properly without me going through and aligning them up manually??Please see link below for example of what I am saying. If it doesnt work, please let me know and I'll make a plan.
Thank you in advance!
1:

Excel - If Table A1:A100 contains a value of A101:A200, then delete row

I have to admit, that I am fairly new to excel and this community.
However, I did try to program a makro what can manage to delete rows in a specific range if a value below matches the one above. (e.g. A1:A100 if it matches a value listet in A101:A200), because the "delete duplicates" tool doesn't seem to work.
Maybe you guys can give me a good answer / macro-code, which can perfon this kind of action.
greetings, valerius21
OK, your 1st comment substantively changes the question. It's not that Remove Duplicates doesn't work - you're not actually trying to remove duplicate values - you're trying to remove items from one list where the Client ID is in the other list.
In a new column of the list you want to delete FROM, use the VLookup function to find matching values from the other list. Then, use the Filter feature to find all of the matching value rows (the ones whose value you were able to successfully look up) and delete those.

Query several ranges and add automatically a column to know the source of each row

I am trying to achieve the following in Google Spreadsheets.
First, I want to query several ranges (in different sheets from the same spreadsheet). I tried a formula like this =query(arrayformula({indirect(E2:E10)}),"select * where Col1 <>''") with no success
In E2:E10 I have a list of ranges. Column F contains a name that describes the source of the value in Column E.
My second problem is that I need to add a column to the output of that query that tells me the origin of each row.
If the sources are ranges of 3 columns by country I need to merge those tables and add that country to each row.
All credits to +Ben Liebrand who helped me out here: https://support.google.com/docs/profile/3464
"I just want to start of by saying that the indirect() function does not work in an arrayformula() function as expected. So you will need to take another approach. I can understand what you are trying to do so I added another TAB in your spreadsheet to demonstrate another approach. I know it was initially a specific design you were trying so I made some changes to what you had. Maybe you can take a look at what I have offered and maybe you can tweak your design.
I know what I am offering is just very rough but you will also notice that I removed the end row specifier from your ranges in the range table.
Don't assume my example to be the final result but I was just trying to show that the range you were trying to use with the indirect() function will not work.
So hopefully this will give you a new idea of how you can maybe handle this.
My formula also adds the country to each of the tables in the output. My formula looks like this
=query(ArrayFormula({
if(len(indirect(regexextract(F2,"\w+\!\w+")&":A")),G2,),indirect(F2);
if(len(indirect(regexextract(F3,"\w+\!\w+")&":A")),G3,),indirect(F3);
if(len(indirect(regexextract(F4,"\w+\!\w+")&":A")),G4,),indirect(F4);
if(len(indirect(regexextract(F5,"\w+\!\w+")&":A")),G5,),indirect(F5);
if(len(indirect(regexextract(F6,"\w+\!\w+")&":A")),G6,),indirect(F6);
if(len(indirect(regexextract(F7,"\w+\!\w+")&":A")),G7,),indirect(F7)
})," select * where Col1 <> '' ")
Hope this is of some help to you"
And I hope is useful to the community
GerĂ³nimo

Find number of Unique Values per Item in Column B

I have a Column B with part numbers. These may repeat and can occur in the same warehouse, (Column A) and also different warehouses. I want to find the amount of times any particular part number appears in a unique warehouse.
I have tried a PivotTable and do not know if I need a macro or just a formula.
How might I achieve this?
Sorry, I think Remove Duplicates and Filter Advanced may not be your best bet. But as I understand your requirement a PT should suit:

Excel - How do I find all relevant rows by typing unique invoice# listed Col A

I have a Worksheet with 10 columns and data range from A1:J55. Col A has the invoice # and rest of the columns have other demographic data. Goal is to type the invoice number on a cell and display all the rows matching the invoice number from col A.
Besides auto filter function, the only thing comes to my mind is VBA. Please advice what is the best way to get the data. Thanks for your help in advance.
Alright, I'm pretty proud of this one. Again avoiding VBA, this one uses the volatile formula OFFSET to keep moving its VLOOKUP search down the table until it's found all matches. Just make sure you paste enough rows of the formula that if there are many matches, there's room for all of them to appear. If you put a border around your match area then it would be clear if you ever ran out of room and needed to copy down the formula some more.
Again, in the main section, it's just a single formula (using index):
=IFERROR(INDEX($A$1:$J$200,$M3,MATCH(N$2,$A$1:$J$1,0)),"")
This gets to be so simple because the hard work of the lookup is done by an initial column which looks up the next row that matches the invoice number. It has the formula:
=IFERROR(MATCH($L$2,OFFSET($A$1:$A$200,M2,0),0)+M2," ")
Here is the working example that goes with those formulas:
Let me know if you need any further description of how it works, but it mostly uses the same rules as above so that it's robust in copying and moving around.
I've uploaded the Excel file so you can play with it, but everything you need to reproduce this feature should be in this solution.
Google Docs - Click link and hit Ctrl+S to download and open in Excel.
A popular solution to this problem is a simple VLookup. Lookup the invoice the user types in on the table A1:J55, and then return an adjascent column's data.
Here's an example of it working:
The formula in the highlighted cell is:
=VLOOKUP($L3,$A:$J,MATCH(N$2,$1:$1,0),FALSE)
What's nice about this formula is you only need to type it once and then you can copy it across and it'll automatically pick out the correct column of the table (that's the match part). The rest is very simple:
The first part says lookup value $L3 (the invoice number typed in),
The second part says look it up in range $A:$J (which is where your table is located). I've shown how you can select the entire columns $A:$J so that you can add and remove data without worrying about adjustin the range in your lookups. (Excel takes care of optimizing the formula so that unused cells aren't checked)
The third part picks the column from which the resulting data will be drawn once a matching row is found.
The FALSE part is an indication that the invoice number must match exactly (no approximate matching allowed)
The $ signs ensure that fixed ranges like the location of your source table ($A:$J) and your lookup value ($L3) don't get automatically changed as you copy the formula across for multiple columns.
The formula is pretty easy to adapt if you want to move around your table and the area where you do your lookup. Here's an example:
Bonus
If you want to add a little spiff, you can add a dropdown to the Invoice # field so that the user gets auto-completion and the option to browse existing values like so: