Assigning a Unique ID to each Unique Name in Excel - excel

I have a list of 20+ names in column A. There are some duplicates names in this list.
What I would like to do is assign a number to each of the unique name in the list. If a duplicate name occurs, the number should be duplicated as well.
Here's an example of what I am hoping to do:
Name ID
Alex 1
Allen 2
Bret 3
Dan 4
Dave 5
Dave 5
Harry 6
Joe 7
Joe 7
Tom 8
As you can see, a unique number is assigned to each of the name. Where a duplicate name appears, the original number gets duplicated as well, such as in the case of Dave and Joe.
If possible, I would like to avoid using VBA.
This list is dynamic and changes frequently, so I can't hardcode these numbers to each of the names, which is why I am hoping to get some assistance in developing a formula.

Try this in B2 and fill down.
=IFERROR(VLOOKUP(A2, A$1:B1, 2, FALSE), SUMPRODUCT(1/COUNTIF(A$2:A2, A$2:A2)))

Assuming this data starts with a header in A1:
In B2 put a 1 for your first unique id, then in B3 place the formula:
=IFERROR(VLOOKUP(A3, $A$2:$B2, 2, FALSE), B2+1)
And copy that down

Related

Excel > Exclude a named range from COUNTIFS

I've got a spreadsheet with hundred of rows, each with a unique ID and each designated to a person.
On a different tab is a summary sheet where my formula goes (count of IDs for each person). On a third sheet, I have a named range 'excludes' which has certain IDs included in a single column.
i.e my sheet1 has:
ID Name
1 Bob
2 Bob
3 Bob
4 Shirley
5 Ted
6 Michael
The named range has say IDs, 2 and 3 in it, so I want my COUNTIFS to return the value 1 for Bob.
ID
2
3
Here's my formula but I think I'm missing something:
=COUNTIFS('Sheet1'!A:A,'summary'!$A1,'Sheet1!A:A,"<>excludes")
I want to exclude every ID in the excludes named range from my COUNTIFS result.
Do I need to use sumproduct or something?
Thanks for your help!
Use SUMPRODUCT:
=SUMPRODUCT((B2:B7=D2)*(ISERROR(MATCH(A2:A7,excludes,0))))
If you want countifs then you will need to count the whole and subtract where it exists in the named range:
=COUNTIFS(B:B,D2)-SUMPRODUCT(COUNTIFS(B:B,D2,A:A,excludes))

Excel: Find duplicates in one column, then remove rows based on value in other column

I've been able to find a number of articles that seem to orbit my particular puzzle, but I'm having difficulty carving out the specific solution for it. Using the below image for reference:
ID Name Company Name
5 Dennis E Lantz Boggio Architects, Pc
6 Director Lantz Boggio Architects, Pc
7 Glenn D Lantz Boggio Architects, Pc
8 Director Ge Johnson Construction
9 Evan Da GH Phipps Construction Companies
10 Paul Fog GH Phipps Construction Companies
11 Todd W GH Phipps Construction Companies
I have a mailing list that is organized so each unique contact is placed on an individual row. The list contains columns for Name (column A in my sheet) and Company Name (column B).
If the Name cell was originally empty, a default 'generic' title is entered (e.g. 'Director', as per rows 6 and 8 in the image).
In some cases, there are multiple contacts at the same company (e.g. rows 5-7, 9-11). Occasionally, one of those contacts has a 'generic' name (e.g. row 6).
What I'd like to do:
Search for duplicates in Column B
Then delete the row based on the value in Column A (with me defining the specific values to be sought for)
So in the example image, only row 6 would be deleted because Column B contains a duplicate address, and Column A contains the value 'Director'.
Thank you!
Maybe, in C5 and copied down to suit:
=AND(COUNTIF(B:B,B5)>1,A5=C$1)
with Director in C1.
Then filter ColumnC to select TRUE and delete.
COUNTIF(B:B,B5) searches for the content of B5 throughout ColumnB (the B:B) and returns the count of the instances. B5 is within ColumnB so function will always find at least 1, for duplicates more than one, so >1 should detect that the row in question (5 for example) is not the only instance.
However, similar entries will not be counted - for example those that end in a trailing space, when what is in B5 does not.

How can I remove non-matching values in two different columns and sort in Excel?

I have several columns of data in my Excel spreadsheet.
Originally, I had two different spreadsheets, as they were generated from reports in a software application.
One of the spreadsheets contains the names of individuals who have had transactions with us in the past year. The other spreadsheet contains the names and the phone numbers. I copied and pasted the columns with the names and phone numbers into my spreadsheet with just the names of people who have purchased something from us in the past year.
My ultimate goal is to extract the names and phone numbers of only the names that have purchased something in the past year.
My column for the past year contains 1,002 names, while my master customer list (with phone numbers) contains over 20,000 individuals. I need the phone numbers of all of the individuals that have purchased something from us in the past year, but I don't want to have to manually go through 1,000 names (and, essentially, 20,000+ to find the match).
If I can achieve my goal without having to use VBA, that would be great. If this is the only route I can take, then I will go that route, but I would like to avoid coding if possible. (This is simply due to time constraints.)
The VLOOKUP function is likely the best solution for you. From the Excel documentation, it:
Looks for a value in the leftmost column of a table, and then returns
a value in the same row from a column you specify. By default, the
table must be sorted in an ascending order.
Note well the implication of that last sentence: the column you're searching in (leftmost column of the lookup table) must be sorted in ascending order for this function to produce the correct results.
Taking a simple example, let's say you have Sheet1 in your Excel workbook with the following information:
A B C
1 Name Transactions Phone
2 Sally 3
3 Alice 5
4 Joe 2
5 Jon 1
You need to add their phone numbers to this sheet, from another workbook. Let's say your phone number information in the other workbook looks like this:
A B
1 Name Phone
2 Alice 2222222
3 Bill 3333333
4 Bob 4444444
5 Jim 5555555
6 Joe 6666666
7 Sally 7777777
8 Sue 8888888
9 Tom 9999999
Take the following steps to add the phone numbers to Sheet1 in the first workbook:
Copy the phone information into a blank sheet in the first workbook. Let's call this Sheet2 for this example.
Make sure the phone information is sorted ascending by the Name column (A), because that's the leftmost column and thus the lookup column.
In cell C2 of Sheet1 (the empty phone cell for Sally), enter: =VLOOKUP(A2, Sheet2!A$2:B$9, 2,FALSE).
Drag-copy this formula down to the remaining cells in the Phone column.
Result:
A B C
1 Name Transactions Phone
2 Sally 3 7777777
3 Alice 5 2222222
4 Joe 2 6666666
5 Jon 1 #N/A
Notes:
The second parameter (Table_array - the lookup data range) should not include the column headings. As you can see, it's Sheet2!A$2:B$9 so it includes the information from rows 2 to 9 in columns A and B.
The last parameter (Range_lookup) should be set to FALSE so you don't pick up the information from the closest match. Note how Jon has no matching phone number record, so his Phone is set to "#N/A" - otherwise he would have been assigned Joe's phone number since that's closest match to Jon.
Parameter documentation:
Lookup_value is the value to be found in the first column of the table, and can be a value, a reference, or a text string.
Table_array is a table of text, numbers, or logical values, in which data is retrieved. Table_array can be a reference to a range or
a range name.
Col_index_num is the column number in Table_array from which the matching value should be returned. The first column of values in
the table is column 1.
Range_lookup is a logical value: to find the closest match in the first column (sorted in ascending order) = TRUE or omitted; find
an exact match = FALSE.

Excel macro/formula - replace cell values if value does NOT appear in another column

I need help. I have a list of 20 names of certain consultants. I receive a new sheet daily with many names, and if one of them does not match with any of the 20 consultant names, I need to replace the cell value with "X".
E.g.
1. Consultant's list contains John and Mary.
2. Daily list contains 5 names: John, Steve, Dean, Mary and Sue.
3. I now want to replace all the cell which does NOT contain John and Mary with X (thus replace cell with names Steve, Dean and Sue with X)
Help will be appreciated
If your 20-name list is in ColumnA and the daily list in ColumnB each starting in Row1 then in Row 1 and copied down to suit:
=IF(ISERROR(MATCH(B1,A:A,0)),"X",B1)

Return value of last match

I need a formula to return the value of Data for the last match of "Text". Row number is also acceptable. Macro is NOT acceptable. Name column is unsorted and cannot be sorted!
Only column "Name" is used as lookup value. I would rather use a/multiple helper column(s) instead of an array formula.
Row Name Data
1 Joe 10
2 Tom 20
3 Eva 30
4 Adam 40
5 Tom 21
LARGE only works with numbers, and VLOOKUP only returns the first match. LOOKUP only works sometimes, so its out too.
So if I wanted the last match for "Tom" then it should return "21".
Array formulas could be avoided with a helper column.
Suppose to have in F1 the name to match (i.e. Tom)
In the helper column row C2 enter
=IF(A2<>$F$1,0,row())
Then copy the formulas along your data.
Now the column C contains 0 for the unmatched names and the row number for the matched ones. Maxing the column yield the row of the solution.
Now the result is simple a matter of using the correct offset with the function offset:
=OFFSET(B1,max(C:C)-1,0)
PS: my copy of excel is in italian, so I can't test this english translaction of the formulas.
I think it's the easiest way to make it.
=LOOKUP("Tom";A2:B7)
Create a column with an array formula (enter it with Ctrl+Shift+Enter):
=VLOOKUP(MAX(IF($B$2:$B$6=B2, $A$2:A$6, 0)), $A$2:$C$6, 3, FALSE)
To make sure you did it right, click on the cell, and the formula should be shown encased in curly brackets ({}).
Note: This assumes that "Row" is in A1.
I have come up with a solution, but it requires that numbers in Data are concurrent, like so
Name Data
Joe 1
Tom 1
Eva 1
Adam 1
Tom 2
Tom 3
Eva 2
But thats okay, since that my data looks like that anyway. So if Name is used before then it must be the old highest +1 aka concurrent.
Name is A1 and Data is B1, and this formula goes into C2:
FLOOR(SQRT(2*SUMIF(A2:A7,A2,B2:B7)),1)

Resources