Creating a sublist based on a second column in excel - excel-formula

I have two columns, the first column will have the name of a object, the second is who it belongs to. I want a new sheet for each person to list what they had assigned to them. here is a example:
dog F
cat F
bell S
whistle
bird F
So Fred has a dog, cat, and a bird; Scott has a bell; and no one has a whistle on their page. Now doing a simple IF() i can get it to look like this for Fred's page
TOP OF ROW
dog
cat
bird
And Scott's page will look like
TOP OF ROW
bell
however I want Fred's to look like
TOP OF ROW
dog
cat
bird
and Scott to be the same.
My current train of thought is to use =VLOOKUP($C$1,Items!A2:C1000,3) in a hidden column in D to tell me which row my data is in, (where Column C on Items is a hidden column with the row number of the row and C1 is the search parameter (S or F)), then =IFERROR(CELL("contents",INDIRECT(ADDRESS($D2,2,1,TRUE,"Items"))),"") , however I other than changing my row index of my search array to 1+ the last found item (which i have not figured out how to do) I can not figure out how to continue searching for the next item.
I know C++ and C# but never have coded in VBA before and I rely heavily on the MSDN and to my knowelge there is no MSDN section dedicated to the Excel API.

One way of achieving the list that you are looking for without any VBA code is to make use of the advanced filter.
On sheet 1 the input list is entered as follows
on sheet2 enter the filter criteria (this criteria means contains F in Owned by column)
and finally on sheet3, call the advanced filter function like this
make sure to select copy to another location
select the sheet1 input list as the list range
select the sheet2 filter criteria as the criteria range
and select somewhere in sheet3 as the output range (the copy to entry)
If you prefer to go down the route of excel VBA programming a good first step is to try out the macro recorder in excel (tools - macros - record macro)
good luck!

There is a good way of doing this with functions in excel.
Essentially you need to create a running countif
So in C2 you would have =COUNTIF($B$2:$B2,"F") Obviously the "F" could also be a reference to another cell. If you fill this formula down the range it will expand the range. Eg. in C3 it will say =COUNTIF($B$2:$B3,"F")
This will give you a running total in column C in your example this would mean:
dog F 1
cat F 2
bell S 2
whistle 2
bird F 3
The fact that you have 3 2s doesn't matter because a vlookup will always match to the first match it finds.
This technique has a lot of different applications. And depending on the data you may find it easier to put this on the left of the data so the VLOOKUP will be easier.

Related

Getting Top Values from One Sheet and inputting onto a different sheet

So I'm going to eventually have 3 sheets. Sheet 1 is where I have data (numbers for a category and a name associated with it. Sheet 2 is where I pull the top 5 users for each category. Sheet 3 is where I have a leaderboard for points gained.
Right now I'm trying to work with Sheet 2 (grab the top 5 performers from each category. I'm fairly new to Excel, but after some research it seemed that XLOOKUP would be the way to go. (i'll attach screenshots below.
I'm using this formula:
=XLOOKUP(LARGE('Cases Test for Categories'!$C$18:$C$55,1),'Cases Test for Categories'!$C$18:$C$55,'Cases Test for Categories'!$A$18:$A$55)
however when using it I get all 0's.
Here's a screenshot of values I'm trying to grab from "Warranty Service Request"
and here is a screenshot when applying my formula
The solution I would want is to grab the 5 largest numbers from sheet 1 with the person name as well.
I don't think that XLOOKUP can get you anywhere near what you want but the formula below will get you one step closer.
=INDEX(List,MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0),1)
In fact, it's the explanation of that formula which will be of help. Here we go.
List is a named range, perhaps equal to your 'Cases Test for Categories'!$C$18:$C$55. The reason for using a name is obvious. It's shorter. In my test List = A2:B6, in case you want to reconstruct it. Column 1 has names, column 2 numbers.
The term INDEX(List,,2) specifies the second column of List. You can replace the '2' with a formula to specify different columns of the named range.
In fact, INDEX(List,,1) does specify the first column and INDEX(List,4,1) specifies the 4th cell in that column, and that is exactly what you see in my formula. All of MATCH(LARGE(INDEX(List, ,2),1),INDEX(List,,2),0) just serves to find the row number in List, in this example the number 4.
Of course, LARGE(INDEX(List, ,2),1) returns the largest number in column2 of List. The '1' can be replaced by a formula, for example ROW()-1 which would return 1 if placed in row 2 and count up from there as it's copied down. Try =ROW()-1 in any cell in row 2 and copy the formula down.
MATCH([LARGEST],INDEX(List,,2),0) returns the row number where the largest was found, and that is the number we need to return the name from the first column of List.
This will work perfectly for one column and can easily be modified to work for different columns. Your question doesn't specify how you would like to arrange the 5 results from each category but the formula can be modified a little to accommodate whatever you want. What it can not do is to deal with ties. MATCH(LARGE can only find the first of several identical results.
To break ties in this sort of operation is complicated and must be done ether by helper columns in the data table or using VBA. It's definitely the topic of another question. For now I hope that it's a problem you will not have to anticipate.

Using two values in a sheet to filter and return values from a table in another sheet

I'm fairly new to coding and i've been googling around for the last few hours trying to solve this problem but it seems to be a little beyond what i'm able to do so i would be very grateful for some help
In Sheet1, I have a table which has columns between M - CV (175 columbs). For each column, i have an "ID number" value in row 3. From Row 6 to the end of the table, i have several "search terms" separated by commas in the column CV
In Sheet2, the corresponding "ID Numbers" are in column B. Column AN contains strings.
For each ID Number value in sheet1, i'm looking to find find all the corresponding cells in sheet2 where the ID number in Column B is the same, and Column AN of sheet2 contains at least one of the "search terms" in column CV
For each ID number, i'm hoping to join the entries in Column AN of sheet2 which match the criteria above and paste them into Row 5 of the respective column in Sheet1
I've gone around in quite a few circles trying to do this and i'm back to square 1 with no code to show for it.
I've tried to research both the autofilter function, and using for loops. The research i've done indicates that for loops are rather slow to run for a large data set.
I'm hoping to find a solution which is as easy to read and understand as possible
I hope i've given enough information for everyone to understand and help
THank you in advance
My Excel subscription has expired an I've started using Google Sheets for most of my spreadsheet work, so I tested this there. Some conversion may be required. I did this using formulas, not VBA also, not sure if that changes things for you.
If I understand correctly, you have two sheets with a shared key column, sheet 1 contains search terms across multiple columns, and sheet 2 contains search terms comma delimited in a single column.
With this setup we want to bring the search term column of sheet 2 into the correct row of sheet 1 by key using VLOOKUP. I made a named range in sheets which contained all my data on sheet 2 and called it "dst". My formula was then =VLOOKUP(A2, dst, 7, true) since my key in sheet 1 was in column A, dst was the range I was searching, my column with my delimited search terms was column 7 in relation to dst, and I had ordered sheet 2 by key. I pasted this formula relatively down all rows as needed.
We want to construct a regex string using our search terms across multiple columns in sheet 1, into a single cell. I used =JOIN("|", B2:E2) on sheet 1 since my search terms were in columns B:E, and this resulted in a regex that looked like this for me: alligator|dog|rabbit|lizard where alligator, dog, rabbit, and lizard, were all search terms in that row. Paste down relative as needed.
We want to run our regex against our search target cell containing the comma delimited search terms. I ran =REGEXMATCH(F2, G2) where F2 was my delimited search terms from sheet 2, and G2 was my constructed regex for the row. Paste down relative as needed.
A screenshot of my completed sheet 1:
Once you know which cells have matches you can do whatever you want.

Sum items from different sheets Excel

I have 2 different worksheets like these
I need to have a new summary sheet with the Time spent sum.
Here should be the output:
What is the best way to implement the formula?
I've simulated your situation, creating two tables, one in sheet1, one in sheet2, containing information in cells B3:C5, and I came up with this formula:
=SUM(VLOOKUP(B3;Sheet1!$B$3:$C$5;2);VLOOKUP(B3;Sheet2!$B$3:$C$5;2))
You might get this to work in your situation by creating an extra column, where you concatenate first name and last name (in order to get the VLookup() to work), but I sincerely think there should be easier ways to get this done.
For your information, my table looks as follows:
A B C
1
2 Name Number
3 a X
4 b Y
5 c Z
The mentioned formula gave the sum of the Xs, Ys and Zs.
Lets say i have two sheets:
Sheet 1:
Sheet 2:
In my opinion the easiest way is:
Select the cell you want to paste the results
Go to Data - Data Tools - Consolidate
Press the arrow at Reference: select the first range, press enter and press Add. Do the same for the second range.
Select Left column and press OK
Structure:

Excel - lookup a range of data to match characters in string

I googled like crazy before I came here.
I have 2 columns of information (I have to use alternate data for privacy). See below.
I would like in a 3rd column to look thru the list (or the range) of the first column and return the matching word. For example, I need the 3rd column for the first sentence (There is a cup on the counter) to say "CUP".
I've tried all sorts of combinations of functions and I can't quite get it right.
1st column 2nd column 3rd column
Desk There is a cup on the counter **Result should be: Cup**
Chair You need to plug the cord in
Cup The desk is red
Cord I have a large computer
Computer I put the chair over there
Assuming row 1 is a header row, put this formula in cell C2 and copy down:
=IFERROR(INDEX($A$2:$A$6,MATCH(1,INDEX(COUNTIF(B2,"*"&$A$2:$A$6&"*"),),0)),"")

Convert delimited text in cells to table with unique headers

I have an Excel table with two columns and about 500 rows. In the first column is the name of a company, and in the second column is a list of partners, delimited by a semicolon. For example, one row would look like [Apple][Foxcomm; Samsung; Microsoft; Intel]. There is an unknown number of partners for each partners cell, and some partners appear with multiple companies.
What I'm trying to accomplish is to reorganize this collection of data into a new table, where each column header is a partner (unique, doesn't repeat), and each company that shares that partner is listed below.
So far I've manged to find a formula for splitting the text based on the delimiter semicolon, but it spreads it across the row (predictably). I've also found formulas for transcribing a table by basically switching the rows and columns, but I'm not sure if I'll even need to do so. My main problem seems to be finding the correct way to phrase my searches on Google!
How can I get Excel to do what I'm trying to accomplish? Or, what would be a better way to display this information?
I fear you may be doing more work than really necessary. I think you have most of the components and as I am not sure quite where something is awry an image may help:
Then, assuming Apple is in A2,
=IFERROR(IF(SEARCH(C$1,$B2)>0,C$1,),"")
in C2 copied across to the right (I think as far as GF2) then all these formulae copied down to suit.
Better to TRIM before removing duplicates (switch order of 3. and 4.)
If elegance and re usability is not important, I would suggest that you, for the sake of this example, imagine your starting sheet is called 'sheet foo':
Use a delimited text to columns(they're separated by semicolon)
Then you would need to use the =LEFT and =MID functions to trim the
brackets and semicolons.
Then copy paste values.
Right click 'sheet foo', go to copy\move, and create a copy, we'll
call this 'Sheet bar'
Convert all of the data in 'Sheet bar' to a table (this step is not
absolutely necessary, but it will help me explain) and name the table
'Table bar'
Return to 'Sheet foo'
Then use the remove duplicates tool on each column
Then copy and paste each column on to the end of the following column
until you've got one very long column. (so you would copy lets say
B2:B500, and paste it at C501, then copy C2:C1000 paste it on to
D501, etc. It's okay if they're not all equal number of rows, as
there may have been different occurrences of duplicate data)
Re-apply the remove duplicates tool, and you should have a column
with all of the unique values for partners in 'Sheet foo'
Copy, paste and transpose (ALT - E - S - E - Enter, in order, not at
once) on the same row as your headers
You would now have every possible partner as a column header, in
'Sheet foo'
Delete all of the columns in 'Sheet foo' that contain each company's
partners; this would leave your column structure so your headers are
| company | first partner | second partner | third partner | ... | final partner |
then under each company header do a
=COUNTIF(FirstRowOfTableBar, CompanyHeader)
and anchor 'FirstRowOfTableBar' on the X axis 'CompanyHeader' on the
Y axis. So it would look something like
=COUNTIF('Sheet bar'!$B2:$B10, 'Sheet foo'!B$2)
Then copy and paste this formula for all company's rows, and all
partner's headers.
Now you have a 0 where a company\partner relationship does NOT exist,
and a 1 where a company\partner relationship DOES exist.
Notes:
This could all go terribly wrong if the company column changes order somehow, in which case an even uglier solution involving either index\match, or offset, or perhaps array '=IF' formulas might be needed.

Resources