Excel: How to add a column from other sheet based on a key column? - excel

I have 2 list. Both have a lot of column. I would like to insert a column from Sheet2 to Sheet1 based on a ceratin key column. Also sheet2 have much more rows than sheet1 so it ll be inserted only partly and still there ll be elements with no matches. For an example:
Sheet1:
Names ID Car Color
John 1 Audi Empty
Andy 4 Toyota Empty
Mike 3 BMW Empty
Tony 2 Suzuki Empty
Sheet2:
ID Cost Color
6 200 Blue
3 200 Red
4 300 Green
5 100 Red
1 50 Black
I would like to get the "color" from Sheet2 to Sheet1 by using the "ID". Using Excel 2010. I suspect I need INDEX+MATCH combination, but the examples I can find are not detailed and more simple so I coudn't figure out how to use them.

How about inserting this formula on Column D in the first row, then dropping the formula down:
=VLOOKUP(B1,Sheet2!$1:$1048576,3,FALSE)
Or to find the column that contains "Color", use Index Match Match, as follows:
=INDEX(Sheet2!$1:$1048576,MATCH(Sheet1!B2,Sheet2!A:A,0),MATCH("Color",Sheet2!$1:$1,0))
This will find the value in Column B in Sheet2 and give you the row number, then it will find the Column that contains "Color" and return the Column number, with those two numbers Index will return your color.

Related

Ranking Duplicate String Values in Excel

I have a spreadsheet with string values and need to create a column with the rank (without using the rank function) of the duplicate values from another column.
Please see below for example of the desired outcome where Dupe_Rank is the created column.
Thanks!
Name
Dupe_Rank
John
1
John
2
Dave
1
John
3
Bill
1
Dave
2
let's say "Name" starts from column 'A' and row 2 as in below figure:
then add this formula:
=COUNTIF(A$2:A2,A2)
to cells below Dupe_Rank and then drag(or copy-paste) this formula to all the cells

Compare and Remove Duplicate Rows based off TWO columns VBA

I currently have a code where my duplicates will be removed based off of one column. I would like to join column 1 and column 2 as strings (I think that would be the easiest way) and remove the duplicates. Currently I have the code:
Range("A1:A6").RemoveDuplicates Columns:=1, Header:=xlNo
I would like to have it so it compares column 1 and column 2 TOGETHER.
For example Column 1 has:
(A1) Apple
(A2) Pear
(A3) Pear
(A4) Apple
Column 2 has:
(B1) Red
(B2) Blue
(B3) Blue
(B4) Orange
In this case, only Row 2 and Row 3 are duplicates. Not Row 1 and Row 4 because you would be comparing two columns instead of one.
Thank you! Hope this made sense.
Include the whole range and use Array to include both columns:
Range("A1:B6").RemoveDuplicates Columns:=Array(1,2), Header:=xlNo

compare 2 excel columns with data in adjacent columns

I have seen a few answers which were close to what I am looking for, but can't quite figure it out. I apologize as I am not a programmer, but am tasked with these types of things periodically.
I have a spreadsheet with data in multiple rows. I would like to compare column A with C and have them align, and then the data in B move with column A. (I can rearrange the columns if need be to make this work.
I have this:
Inventory ID# count Original ID# vendor item number
1234 2 1000 vendor 1 1234566
1456 1 1234 vendor 2 546564
7000 3 1456 vendor 3 af4566
2003 vendor 4 56778
7000 vendor 1 788asd
What I want it to look like is after:
Inventory ID# count Original ID# vendor item number
1000 vendor 1 1234566
1234 2 1234 vendor 2 546564
1456 1 1456 vendor 3 af4566
2003 vendor 4 56778
7000 3 7000 vendor 1 788asd
I have tried macros, and VLOOKUP, but can't figure out how to have the count move with the inventory ID # Thank you for your help.
I'll assume your data starts in Sheet1!A1
Move the Invenotry ID# and count columns to a different sheet (say, Sheet2). Then replace the value in cells A2 with the following:
=IFERROR(VLOOKUP($C2,Sheet2!$A:$B,1,FALSE),"")
and similar for cell B2:
=IFERROR(VLOOKUP($C2,Sheet2!$A:$B,2,FALSE),"")
Fill it down. The VLOOKUP will place your id's and counts in the right rows, and the IFERROR( ... ,"") part will put a blank string where there is no match, so it will look like you desired table
If your data starts from cell A1, insert 2 columns C and D like below,
Enter the below formula in cell C2 and drag it right to column D and then down throughout the range,
=IFERROR(INDEX($A:A,MATCH($E2,$A:$A,0),COLUMN(A1)),"")
You can then copy-pastespecial Column C and D to A and B and delete C and D.

Count how many distinct values (or get list of distinct values) in a filtered column

Is there a way to count the number of distinct values in a filtered column in Excel?
Using the formula at https://exceljet.net/formula/count-unique-values-in-a-range-with-countif I can count the number of distinct values in a range, but when that range has been filtered with an auto-filter I still get the unfiltered count.
For example:
A B
1 Scarf Blue
2 Hat Red
3 Gloves Green
4 Coat Blue
5 Balloon Red
6 Shoes Blue
Counting unique values in B with =SUMPRODUCT((B1:B6<>"") / COUNTIF(B1:B6,B1:B6 & "")) should return 3 as the distinct values are Red, Green and Blue.
If I auto filter Column B to just select Red items, the resulting table will look like:
A B
2 Hat Red
5 Balloon Red
In this case the number of distinct values retuned should be 1. But the formula above still returns 3.
The formula should also cope with multiple selections in the auto-filter, so for example filtering for Blue and Green should result in the following table:
A B
1 Scarf Blue
3 Gloves Green
4 Coat Blue
6 Shoes Blue
From which the formula should return 2 (Blue, Green).
Finally, if I am filtering on column A rather than B, the formula should still work. So If I am only interested in Hat, Scarf and Coat, filtering column A for these values would result in:
A B
1 Scarf Blue
2 Hat Red
4 Coat Blue
From which the formula should return 2.
(I'm using Excel 2013 and need to do this in a formula rather than using VBA etc)
I also found this page on office.com which I thought might help, but alas I can't get it to work for me.
This reference shows how you can exclude hidden rows using AGGREGATE
Excluding hidden rows with AGGREGATE
You can then use a standard way of counting unique values like this
Counting unique values with FREQUENCY
So if you were counting values in column B, you would need a helper column (say C) containing
=IF(AGGREGATE(3,5,B2),B2,"")
Then plug in the form of count unique that ignores empty cells
=SUM(IF(FREQUENCY(IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""), IF(LEN(C2:C10)>0,MATCH(C2:C10,C2:C10,0),""))>0,1))
Or your formula if you prefer
=SUMPRODUCT((C2:C10<>"") / COUNTIF(C2:C10,C2:C10 & ""))

Updating a column in excel

I have two excel sheets with one column common for both. I need to match the column value and update the next column by following the excel 2.
for example:
I have excel1 as
A B C D
fruits 22 f.market
vegetables 50 v.market
flowers 60 l.market
excel2
A B
fruits 1000
flowers 2000
So, I need to update column D in excel 1 as 1000 where column A is fruits
You can use VLOOKUP() for fetching the respective value. Considering your data value 'fruits' is in cell A1 try to use following function
=VLOOKUP(A1,$A1$B2,2,false)

Resources