Excel Consolidating Text String (Yes/No) - excel

Trying to combine the data into one master sheet. I have something like below:
Sheet 1 Sheet 2 Sheet 3
Name Gain(Y/N) Name Gain(Y/N) Name Gain(Y/N)
AAA Y AAA Y AAA
BBB N BBB BBB N
CCC CCC Y CCC Y
DDD DDD DDD Y
EEE EEE EEE N
Ultimately would look something like (merging all the sheets into sheet1)
Sheet 1
Name Gain(Y/N)
AAA Y
BBB N
CCC Y
DDD Y
EEE N
The problem is that consolidate function won't work for Text string (Y/N)
I am thinking something like 'if vlookup' or match index? but for multiple reference?
and not overriding each other. Maybe there is simpler way...
Thanks for your help :D

=IF(OR(Sheet1!B2="Y",Sheet2!B2="Y",Sheet3!B2="Y"),"Y",IF(OR(Sheet1!B2="N",Sheet2!B2="N",Sheet3!B2="N"),"N",""))
in B2 of a new sheet and copied down may suit.
Edit Simplification of revised formula to reflect edit to question:
Filter Sheet1 for Gain (Y/N) (assumed to be ColumnB) for (Blanks) and in the cell with the smallest visible row number enter:
=IF(OR(VLOOKUP(A4,Sheet2!A:B,2,0)="Y",VLOOKUP(A4,Sheet3!A:B,2,0)="Y"),"Y",IF(OR(VLOOKUP(A4,Sheet2!A:B,2,0)="N",VLOOKUP(A4,Sheet3!A:B,2,0)="N"),"N",""))
Change 4s in A4s to smallest visible row number (adjust column references as necessary) and copy down as required.

If you don't mind creating an extra column on each sheet, you could turn "Y" and "N" into a number. Assuming your labels are in column A, you insert a new column B and put the following in B2:
=IF(A2="Y", 3, IF(A2="N", 2, 1))
Repeat for all sheets. Now you can do consolidation, using the "MAX" function. It will return 2 if the letter "Y" appeared anywhere, etc. Now you can get back to Y/N/blank by putting the following formula in a column next to the consolidated data:
=INDEX({" ","N","Y"}, B2)
This will return " " if B2 is 1, "N" if B2 is 2, etc. Finally you can copy the entire column, and "paste special - values" to get exactly what you wanted.

You might as well use Microsoft Query to fetch all the data into a pivot with a code similar to this:
SELECT Name, Gain, 'Sheet1' as [Sheet#]
FROM Sheet1
UNION
SELECT Name, Gain, 'Sheet2' as [Sheet#]
FROM Sheet2
UNION
SELECT Name, Gain, 'Sheet3' as [Sheet#]
FROM Sheet3

Related

Excel: Transpose data from rows to column headings

My problem, as the title states, has to do with transposing data from rows to columns
The original data came into a csv format where in the second column 'Dates and Rank' semicolons and spaces acted as delimiters.
Country Dates and Rank
Switzerland [2014-03-07] 7;[2014-10-17] 7;
USA [2011-07-01] 7;[2012-02-17] 7;[2012-09-30] 7;[2013-01-31] 7;
France [2011-07-01] 4;[2012-02-17] 4;[2012-09-30] 4;
China [2015-01-16] 7;[2015-03-06] 7;[2015-10-16] 7;[2015-10-23] 7;
So, by using the Text to Columns function from excel I separated the data within 'Dates and Rank' column into different cells. And now the result looks like this:
Country Dates and Rank C D E F G H I
Switzerland [2014-03-07] 7 [2014-10-17] 7
USA [2011-07-01] 7 [2012-02-17] 7 [2012-09-30] 7 [2013-01-31] 7
France [2011-07-01] 4 [2012-02-17] 4 [2012-09-30] 4
China [2015-01-16] 7 [2015-03-06] 7 [2015-10-16] 7 [2015-10-23] 7
*I have also deleted the square brackets from the dates and I assigned them as YMD cells.
But what I need to do now is to use the dates as headings while I use the rank (1-7) as their allocated data within the cells. For example:
Country 2011-07-01 2012-02-17 2014-03-07 2014-10-17
Switzerland 6 7
USA 5 7
Any suggestions please?
Thank you.
I'll assume your data starts in cell A1 (i.e. A1 contains "Country").
First, create a new worksheet where your newly ordered data will come. You first need to fill in the column header row. You can do this by
manually copy-pasting all the date columns from your original data to a single column in the new worksheet, so that all dates are in one column
Remove duplicates (in the ribbon: Data > Data Tools > Remove Duplicates)
Sort the list if you want (Data > Sort & Filter > Sort)
Select the resulting data, copy, and transpose-paste in cell B1 (Home > Paste > Paste Special, and check the box "transpose"). Now you can also remove the data you just copied.
Second, copy-paste column A of the source worksheet into column A of the destination worksheet.
Finally, for each country and each date you want to look up the data right next to the date. You can do this by using the following formula in B2:
= IFERROR( INDEX( Sheet1!2:2, 1, MATCH( B$1, Sheet1!2:2, 0 ) + 1 ), "" )
Finally, copy this formula down and across.
This should do the trick just fine, but it is not a very flexible solution and you need to follow the steps exactly as explained. For example, if the countries are in a different order than they are in your original data sheet, it won't work.

Need to match data in different sheets and replace data in another cell if it's a match

I need to match data in column A2 and so on in sheet 1 to data in column A2 and so on in sheet 2. If the data in column A of sheet 1 and sheet 2 match I need the data in column B & C of sheet 2 to replace data in column B & C of sheet 1. I know VERY little about doing this kind of stuff so any help would be GREATLY appreciated!
SHEET 1
A B C
2 12345 5.35 9.95
3 15874 4.22 10.99
4 11111 2.24 5.99
5 98745 5.33 9.95
6 88552 4.24 8.95
SHEET 2
A B C
2 11111 2.09 5.79
3 12345 5.11 9.89
4 88552 4.01 8.79
NEED SHEET 1 to change to
A B C
2 12345 5.11 9.89
3 15874 4.22 10.99
4 11111 2.09 5.79
5 98745 5.33 9.95
6 88552 4.01 8.79
On a third sheet use these functions
column a ='sheet1'!a2
column b =if('sheet1'!b2='sheet2'!b2,'sheet2'!b2,'sheet1'!b2)
column c =if('sheet1'!c2='sheet2'!c2,'sheet2'!c2,'sheet1'!c2)
Copy sheet3 and paste the values into sheet1.
This should work unless column a does match. or if you need to do this dynamically. If column a doesn't match some vlookups can be thrown in.
I your data does match in column a your formulas could look something like this.
column a ='sheet1'!a2
column b =if(not(iserror(vlookup(a2,'sheet2'!a:c,2,false))),vlookup(a2,'sheet2'!a:c,2,false),vlookup(a2,'sheet1'!a:c,2,false))
column c =if(not(iserror(vlookup(a2,'sheet2'!a:c,3,false))),vlookup(a2,'sheet2'!a:c,3,false),vlookup(a2,'sheet1'!a:c,3,false))
this is too much to put in a comment so I'm putting it in answer.
The way I under stand is, since sheet1 has more data, you only want to be doing this comparison when sheet1 and 2 both have data on the row. so If sheet1 has data in rows 1 - 100, and sheet2 has data in rows 1 to 50, you only want to be doing this comparison for the first 50 rows in sheet1 right?
So, rather than copying and pasting formulas, what you can do is, in sheet1, find an unused column. go to the first row. in the formula box, type: "=if(" without the quotes. now, select the first cell to compare, according to your example you'd select sheet1, A2. then type "=" without quotes. then select the second cell you want to compare - in your example, sheet2, A2. then type "," without quotes. then select the cell from which you want the data if the first 2 cells are equal. in your example, sheet2 B2. then type "," without quotes, then select the cell with the data to use if the first 2 cells are not equal. in your example, sheet1 b2. then type ")" without the quotes.
so using your example, the function would look similar to how bigtree had it: =if('sheet1'!A2='sheet2'!A2,'sheet2'!b2,'sheet1'!b2)
so, this will compare sheet1 cell A2 with sheet2 A2 and if they are equal, the cell you put the formula in will the have the value of sheet2 b2, and if they are not equal, the cell with this formula will have the value of sheet1 B2. then, drag this formula down for however many rows you want, and the formula will adjust automatically for each row. you'll see the numbers increase. then, select the column with the formulas, right click and select copy, then right click and go to paste special, and click values. this will make it so the column contains only the values, not the formulas, now you can paste this data in column B sheet 1.
you can reuse this formula for whatever columns, just follow the steps.
HTH, good luck!

Find value from one cell, copy value from cell near to that cell and paste it to another sheet

I have 2 sheets with different values. I need to find a value from one cell.sheet1 in sheet2 and copy value from nextcell_in_the_same_row.sheet1 to nextcell_in_the_same_row.sheet2.
It is very difficult to explain let look at the example bellow.
E.g.
Before
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa
2 ada
3 cca
4 ccc
After
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa *need to find value in the first sheet and copy value from B2 because aaa in A1*
2 ada *value does not exist in the first sheet so copy nothing*
3 cca *not need to copy because no value in the first sheet*
4 ccc *need to copy the value from B3*
Thank you so much!
Use a VLOOKUP along with an IFERROR.
=IFERROR(VLOOKUP(A1, Sheet1!A:B, 2, 0), "")
This will do what you described (well described, by the way!) in your question. Drag the formula down in Sheet2 till the bottom.
VLOOKUP takes the value of A1 in sheet 2 (no sheet reference because the value is in the same sheet as the formula) and looks it up in column A of Sheet1.
It returns the second value (hence why 2) of the table selected in the formula (column A is 1, column B is 2).
The 0 tells the VLOOKUP to look for exact matches. You don't need approximate match here.
And IFFERROR is there in case VLOOKUP doesn't find anything (like with ada) and instead of giving #N/A, returns an empty cell, "".

Add cell string to another cell if 2 cells are the same for 2 rows

I'm trying to make a macro that will go through a spreadsheet, and based on the first and last name being the same for 2 rows, add the contents of an ethnicity column to the first row.
eg.
FirstN|LastN |Ethnicity |ID |
Sally |Smith |Caucasian |55555 |
Sally |Smith |Native American | |
Sally |Smith |Black/African American | |
(after the macro runs)
Sally |Smith |Caucasian/Native American/Black/African American|55555 |
Any suggestions on how to do this? I read several different methods for VBA but have gotten confused as to what way would work to create this macro.
EDIT
There may be more than 2 rows that need to be combined, and the lower row(s) need to be deleted or removed some how.
If you can use a formula, then you can do those:
Couple of assumptions I'm making:
Sally is in cell A2 (there are headers in row 1).
No person has more than 2 ethnicities.
Now, for the steps:
Put a filter and sort by name and surname. This provides for any person having their names separated. (i.e. if there is a 'Sally Smith' at the top, there are no more 'Sally Smith' somewhere down in the sheet after different people).
In column D, put the formula =if(and(A2=A3,B2=B3),C2&"/"&C3,"")
Extend the filter to column D and filter out all the blanks.
That is does is it sees whether the names cells A2 and A3 are equal (names are the same), and whether the cells B2 and B3 are equal (surnames are the same).
If both are true, it's the same person, so we concatenate (using & is another way to concatenate besides using concatenate()) the two ethnicities.
Otherwise, if either the name, or username, or both are different, leave as blank.
To delete the redundant rows altogether, copy/paste values on column D, filter on the blank cells in column D and delete. Sort afterwards.
EDIT: As per edit of question:
The new steps:
Put a filter and sort by name and surname. (already explained above)
In column E, put the formula =IF(AND(A1=A2,B1=B2),E1&"/"&C2,C2) (I changed the formula to adapt to the new method)
In column F, put the formula =if(and(A1=A2,B1=B2),F1+1,1)
In column G, put the formula =if(F3<F2,1,0)
In column H, put the formula =if(and(D2="",A1=A2,B1=B2),H1,D2) (this takes the ID wherever it goes).
Put the formulae as from row 2. What step 3 does is putting an incremental number for the people with same name.
What step 4 does is checking for when the column F goes back to 1. This will identify your 'final rows to be kept'.
Here's my output from those formulae:
The green rows are what you keep (notice that there is 1 in column G that allows you to quickly spot them), and the columns A, B, C, E and H are the columns you keep in the final sheet. Don't forget to copy/paste values once you are done with the formulae and before deleting rows!
If first Sally is in A1 then =IF(AND(A1=A2,B1=B2),C1&"/"&C2,"")copied down as appropriate might suit. Assumes where not the same a blank ("") is preferred to repetition of the C value.

Find Results in excel copy the rows to another sheet

I need some help copying data from one excel worksheet to another. For example:
Sample Data
__A__B___C
1 aaa bbb ddd
2 bbb ccc eee
3 ccc fff rrr
4 ccc fff ttt
5 ddd eee ggg
6 aaa ddd eee
7 bbb fff hhh
8 eee eee eee
So for the above records if I do a 'CTRL + F' and search to find All 'eee' the results will show 6 instances in C2, B5, C6, A8, B8, C8
Now I want to copy the whole of rows 2,5,6 and 8 to another worksheet.
This worked for me... a simple solution:
Select/highlight the data you want to search
Press ctrl +h for Replace
Enter the string you want to find in "Find What".
Select "Replace with" Format, then Format > Fill and choose a background fill, doesn't matter what color. Then click [Replace All].
Then choose on the Excel menu > Data > Sort on "Cell Color",
Order (the color you chose from step 4 above) and then "On Top" or "On Bottom" - whatever you want, click [Ok].
Now all the data you wanted is all in one block of rows. Copy and paste to another worksheet as required.
To achieve what you need please do the following (assuming your data is located in columns A:C starting row 2, i.e. there are headers):
Type in D2 (additional column): =IF(OR(A2:C2="eee"),1,0), but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
Autofill formula as required.
Add filter to the whole A:D range.
Apply filter to column D for value 1.
Copy entire filtered columns A:C and paste anywhere - only filtered rows will be copied.
Sample file: https://www.dropbox.com/s/qscwbf5kbnwi5pa/Filtering3Columns.xlsx
I think what you are looking for is called VLOOKUP just take the Excel-help, theres everything explained
The easiest way I found was this: Using the option "Sort & Filter" located in the right upper corner. Then you can filter any column by any criteria you like. By doing that only the filtered rows appear on the spread sheet (the rest are still there but just hidden). From there you can easily copy and paste the entire rows.

Resources