Sorting rows by matching values in two different columns - excel

I have to look through my worksheet to find duplicate entries on the basis of two columns - column A and column D. If entries under both these columns match in any two given rows, then I consider them duplicated. In order to do this, I have been trying to sort the rows such that rows with matching entries under column A and column D appear one below the other. For example, if I have:
Col A Col B Col C Col D
ABC PQR 123 456
ABC XYZ 789 006
ABC BNM 376 456
ABC QWR 387 006
Preferably through VBA, I want to be able to put it in the format:
Col A Col B Col C Col D
ABC PQR 123 456
ABC BNM 376 456
ABC XYZ 789 006
ABC QWR 387 006
I am aware of how to sort by one column but not sure if there is a way to do it by two. There are more than 5000 rows in the worksheet and more than 50 columns and I would like to be able to sort these quickly for comparison.

Excel has built-in functions to help you with the issue (no VBA required).
Select the cells including your data and navigate to "Data - Sort & Filter - Sort". There you can add different levels of sorting (e.g. sort by Col A first, then by Col B, ...).
If the duplicates need to be removed this can be done directly as well. Select the cells including your data and navigate to "Data - Data Tools - Remove Duplicates". You can select the columns which need to match in order for Excel to remove the duplicates.

Related

find string in other column but same row vba

some cells in column D contains same numbers "123".
The macro needs to find the row of the string "xxx" in different column but same row that contains numbers "123".
This seems like a good INDEX(MATCH) use case.
If your table is something like
Col1
Col2
Col3
A
xxx
111
B
yyy
222
C
zzz
333
You can try something like
=INDEX(A2:C4,MATCH(B2,B2:B4,0),3)
Which will return 111 as you matched the row containing xxx and wanted column 3

OFFSET function in Excel for Dynamic Table Named Range

I am working with a dynamic data range, so whenever new columns or rows are added either as the last column / row OR anywhere within the data range it would update the records.
I created an OFFSET function for a dynamic data range:
=OFFSET(Data!$A:$A,0,0,COUNTA(Data!$B:$B),COUNTA(Data!$1:$1))
But the issue is that it is updating new columns inside the existing columns.
I honestly have tried several other ways but without success.
Example table:
Column A Column B Column C
Need to Add Column D between Column A and Column B
Desired Output:
Column A Column D Column B Column C
123 456 789 10 11
But I am getting:
Column A Column B Column C
123 789 10 11
456 789 10 11
456 789
456 456
123
123
Column D column has not been added but has just been updated in the cells within the Column A and B
Which is not what I am looking for

how to find non unique combinations of two variables in Excel?

I have two columns in Excel that identify individual records (ID and code). Some of these may occur multiple times. For some records, the code may be missing. And some IDs belong to multiple codes. I need to find these IDs that have non unique associations with a given code, and show what those are.
Minimal example:
ID code
K151 ABC
K152 BCD
K153 EFG
K154
K151 ABC
K154 HDG
K153 EFF
K151 ABC
K153 EFG
So I need to have a list (possibly with the number of occurences):
ID code freq
153 EFG 2
153 EFF 1
154 1
154 HDG 1
It is fairly easy to do something similar using a Pivot Table, but note that e.g. K151 - ABC occurs 3 times, and it should not be listed, just those IDs that have multiple codes. Also, in the pivot table the codes are collapsed under the ID as parent category and they are not shown side by side.
It is also OK, if the non-uniquely coded IDs are flagged in the original table in a new variable, and then these records can be filtered manually using the flag.
ID code flag
K151 ABC 0
K152 BCD 0
K153 EFG 1
...
K153 EFF 1
...
I need to find a solution in Excel (2013), not VBA or anything else, and ideally the solution should also be compatible with LibreOffice Calc.
The flagging will be simple.
Formula in C2 downwards:
=COUNTIF($A:$A,"="&A2)<>COUNTIFS($A:$A,"="&A2,$B:$B,"="&B2)
Formula in D2 downwards:
=IF(C2,COUNTIFS($A:$A,"="&A2,$B:$B,"="&B2),0)
For OpenOffice we need SUMPRODUCT because COUNTIF will not count if blank.
Formula in C2 downwards:
=COUNTIF($A$1:$A$20,"="&A2)<>SUMPRODUCT(($A$1:$A$20=A2)*($B$1:$B$20=B2))
Formula in D2 downwards:
=IF(C2,SUMPRODUCT(($A$1:$A$20=A2)*($B$1:$B$20=B2)),0)
Copy and paste the first two columns in a different location.
Select the data and Use Remove Duplicates tool in the Data tab.
Start third column and use COUNTIFS for multiple column criteria to get the count of each row.

Equation/ sorting to separate one long column of data into separate columns

I have two columns of data in an excel spreadsheet that is listed like, each date has three numbers associated with it. It is shown like this:
1 112
1 123
1 456
2 788
2 989
2 901
What I am trying to do is have the data shown like this:
1
112
123
456
Then in another column next to it have;
2
788
989
901
Okay, this can be done pretty easily/quickly.
First, select your entire column that has # ### and go to Data --> Text to Columns, and choose “Delimited”, then use a “Space” delimiter. This will separate your numbers by the space, so 1 and 2 will be in Column A, and the three digit numbers are in B (or wherever you decide to put them).
Then, just get the unique values from column A. I tend to copy the entire column to a temporary column (or worksheet), then highlight them and go to Data --> Remove Duplicates. Now you have a list of unique numbers. Copy and paste these (transposing) into (for example) column D.
Then, in D2, enter this formula (adjust ranges as necessary) as an array, using CTRL+SHIFT+ENTER:
=IFERROR(INDEX($B$1:$B$6,SMALL(IF($A$1:$A$6=D$1,ROW($B$1:$B$6)-ROW($B$1)+1),ROWS($B$2:$B2))),"")
Here’s a screenshot of the final output:

Find duplicates with a suffix in excel and keep results

I have a spreadsheet with a list of items in one column (A) and in column C shows the total sold. I'm trying to find all the items within column A.
The issue is, some items are the same, only they have a suffix, mostly separated by a -. The values in column C would be different as well.
Example:
ABC = 5
ABC-123 = 3
ABC-543 = 2
I'm looking to identify only 123 and then combine all the values, so that it will show ABC and 10 as the total.
I've looked around how to remove the duplicate suffix, but have so far failed to find a method when trying to add the total values.
Many thanks
do you mean the data you have looks like this:
column A column B column C
ABC 5
ABC-123 3
ABC-543 2
if so, you can select column A then go to data then text to columns then delimited select other by putting - sign, next and finish.
result must be:
column A column B column C
ABC 5
ABC 123 3
ABC 543 2
then you can =sumifs(C:C;A:A;"ABC") (keep in mind that column B must be empty)
if you have ABC-123 = 3 in the same cell as a text, then you can do:
=IF(SEARCH("ABC";F3);RIGHT(F3;LEN(F3)-FIND("=";F3)-1);"")
where F3 is equal to ABC-123 = 3 The formula above searches fo ABC and gives you a value after = sign, no matter how long this value is. If there is no ABC it will return an error.
if there is no need to look for ABC then just use:
=RIGHT(F3;LEN(F3)-FIND("=";F3)-1)
I hope this helps. I cannot comment, so ask if you have questions.
Best - AB

Resources