Compare and Remove Duplicate Rows based off TWO columns VBA - excel

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

Related

Stacking two list of data on top of each other in excel

I have two excel sheets with one column each.
Sheet1
A
Fruits
Orange
Apple
Grapes
Sheet2
B
Vegetables
Tomatoes
Potatoes
Now, how do I use excel formula and populate on a third sheet stacking just the values
A
Orange
Apple
Grapes
Tomatoes
Potatoes
If your data has a header in Sheet1!A1 and Sheet2!A1 then in Sheet3!A1 you could use (and drag down):
=IF(ROW()<=ROWS(Sheet1!$A$2:$A$4),
Sheet1!A2,
SUBSTITUTE(
INDEX(Sheet2!A:A,
ROW()-ROWS(Sheet1!$A$2:$A$4)+1),
"",""))
If the row number in the new sheet is smaller than or equal to the count of rows in the range of Sheet1 then the result is Sheet1!A2:A4 if the row is greater it'll index Sheet2 column A and will get the result for in that range with the row that equals to the current row number minus the total count of rows of Sheet1!A2:A4 + 1 to take the header into account.
In Office 365 a simple =HSTACK(Sheet1!A2:A4,Sheet2!A2:A3) would do.

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

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.

Count the cells that value in excel

I want to get the count of cells in each row that has a value in it.
ross dan bernard 3
mary 2
rose johnny 2
I want a formula that gives counts the non blank values in each row and gives the value in column E (ie., 3,2,2)
You can use the CountA function:
=COUNTA(A1:Z1)

Match name and copy row from sheet 1 to sheet 2 on corresponding column

I asked a very similar question to this one here, but I am trying to identify if a cell's numerical value is contained in a list of cells on a different sheet. If the cell from sheet A matches a cell in sheet B, mark a different column in B with a corresponding row in sheet A, otherwise leave it blank. An example is below:
Sheet A
Column A | Column B
-------------------
1 John
2 Sue
4 Bob
I would like the corresponding Sheet B to populate Column B like this:
Sheet B
Column A | Column B
-------------------
2 Sue
3
4 Bob
=IF(ISNUMBER(MATCH(I2, 'SALT, WOD, Champion Members'!A:A, 0)), "Y", "N")
I have been using the above answer to populate a different column in the same workbook, and I'm thinking I can maybe use this formula, but instead of "Y" or "N", somehow preserve the row.
You need to use VLOOKUP as already mentioned. But you will need to use another function to check for existence of the value, else you will get #N/A against ID 3
I used COUNTIF
=IF(COUNTIF($A$2:$A$4,E2)=0,"",VLOOKUP(E2,$A$2:$B$4,2,FALSE))
Use the VLOOKUP function:
=VLOOKUP(A1;Sheet1!A:B;2;FALSE)
Where A1 is the value you want to look up, Sheet1!A:B is the original sheet with the data.

How to compare 2 cells to another 2 cells in a different sheet in excel?

I want to know how to compare or know the difference of 2 cells to another 2 cells in a different sheet in excel 2007
Example:
Sheet 1
A B
1 101 KIWI
2 102 APPLE
3 103 BANANA
Sheet 2
A B
1 101 KIWI
2 102 APPLE
3 103 ORANGE
I want to show the there is a difference in 3rd row on Sheet 1 and 2
Thanks
If you put =A1&B1 in C1 of each sheet and copy down then it is like comparing single columns. So with, in D1:
in Sheet1: =MATCH(C1,Sheet2!C:C,0)
in Sheet2: =MATCH(C1,Sheet1!C:C,0)
copied down in each case the resulting numbers should show the row number where the match is on the 'other sheet' (the lists need not be sorted) and otherwise #N/A for where matches have not been found.
There is obviously no need for the concatenation for the example provided, since the two 'A' columns are identical, but I take it that was because the example was simplified.

Resources