Find a list of words in an excel sheet - excel-2016

I am trying to find a list of words and if the word(s) exist then a count of each word) in an excel sheet which has multiple columns. For example:
Words to find
Apple
Banana
Kale
Chard
Excel sheet columns
ID Name Feedback_1 Feedback_2
121 John I don't like Bananas Bananas
122 Adam Kale is good Apple
123 Rob Chard sucks Kale
Output
Apple 1
Banana 2
Kale 2
Chard 1

Try
{=SUMPRODUCT(--(IFERROR(FIND(G1,Rng_Feed),0)>0))}
where Rng_Feed is a continuous range of Feedback_1 and Feedback_2. You can use $C$2:$D$5 if you do not want to name this range nor use it in the formula.

Related

Retrieve match from list of strings and add as column in dataframe

I have a dataframe which contains columns text and user.
user
text
Tom
I love bananas
Dick
I love apples
Harry
I love apples and bananas
I want to find rows of text which contain a list of fruits. For
each matched string, a new row is added to new columns fruits and fruits_with_colors. The expected output is below:
user
text
fruits
Tom
I love bananas
bananas
Dick
I love apples
apples
Harry
I love apples and bananas
apples
Harry
I love apples and bananas
bananas
I'm having some trouble thinking about how to do this. I was doing the following using pandas:
fruits = ['apples', 'bananas']
df_with_matches = df[df['text'].str.contains('|'.join(fruits))]
but am returning the error sequence item 0: expected str instance, list found
You can use str.findall to extract fruits into a list and then explode it:
df.assign(fruits = df.text.str.findall('|'.join(fruits))).explode('fruits')
user text fruits
0 Tom I love bananas bananas
1 Dick I love apples apples
2 Harry I love apples and bananas apples
2 Harry I love apples and bananas bananas

Convert multiple rows into a single comma separated string without XML

I want to combine data from multiple rows into a single comma separated string without using the XML function as it is not supported.
Here is an example:
ID Food
1 Apple
1 orange
2 wine
2 whiskey
2 beer
3 rice
3 wheat
3 maize
3 quinoa
Note that number rows per id is not fixed
Output:
ID Foods
1 Apple, orange
2 wine, whiskey, beer
3 rice, wheat, maize, quinoa
#standardSQL
select id, string_agg(food) as foods
from `project.dataset.table`
group by id

Excel VBA - Group Data by Column A, Get the Range Value from C - Copy results to New Sheet

I've been trying to search for an example of this grouping and tested few code snippets but haven't been able to adapt it to what I need as I'm just getting to know Excel vba.
What I'm trying to do is to group by column A then get the range of the values used in that category which are in column C and get the results in a new worksheet.
Main Sheet.
A B C D
3 Baseball 4 Blue
2 Football 1 Red
2 Football 3 Red
3 Baseball 4 Blue
1 Soccer 2 Green
3 Baseball 4 Blue
1 Soccer 3 Green
1 Soccer 5 Green
2 Football 2 Red
Expected Results:
New Sheet.
A B C D
1 Soccer 2-5 Green
2 Football 1-3 Red
3 Baseball 4 Blue
If you need column C to be a range of value, eg 2 - 5, then it's text in Excel. Pivot table only able to return Min, Max, Sum, Average, but not range of the value.
You will need using VBA to solve the problem.
First, copy column A,B,D to some where, then using Remove Duplicate.
To find out the Unique combination.
Eg: (Assuming you have some new records in future)
A B C D
3 Baseball 4 Blue
2 Football 1 Red
2 Football 3 Red
3 Baseball 4 Blue
1 Soccer 2 Green
3 Baseball 4 Blue
1 Soccer 3 Green
1 Soccer 5 Green
2 Football 2 Red
4 Tennis 3 Yellow
Then you should have something like below:
A B D
1 Soccer Green
2 Football Red
3 Baseball Blue
4 Tennis Yellow
Then using Loop, to find out the range of the value for each of the Unique Combination (here we have 4 unique records).
*** assume that you know how to use loop to find out the Range of each combination.
I've actually figure this out:
For Each key In fCatId.Keys
'Debug.Print fCatId(key), key
With wshcore
llastrow = wshcore.Range("A" & Rows.Count).End(xlUp).Row
.Range("A1:N" & llastrow).AutoFilter
.Range("A1:N" & llastrow).AutoFilter Field:=1, Criteria1:=fCatId(key)
lwmin = WorksheetFunction.Subtotal(5, Range("H:H"))
lwmax = WorksheetFunction.Subtotal(4, Range("H:H"))
Im getting column a: fcatid, b: key, lwmin: lowest value and lwmax: highest.

Linking worksheets based on a pivot column

I have a spreadsheet linking issue. For example let the data in the work books look like this
Book1
A 1 aaa
B 2 bbb
C 3 ccc
Now I link this sheet to another sheet by reference and it has same values as in here
Book 2
A 1 aaa
B 2 bbb
C 3 ccc
Now if I add another column in Book 2 like below
Book 2
A 1 aaa 10
B 2 bbb 20
C 3 ccc 30
Now if I link this new column back to Book1 it looks like below
Book 1
A 1 aaa 10
B 2 bbb 20
C 3 ccc 30
But now if I sort column 1 in book 1 it doesn't sort the column4 because that is referenced to Book 2 which looks like below
Book 1
C 3 ccc 10
B 2 bbb 20
A 1 aaa 30
But expected output is
Book 1
C 3 ccc 30
B 2 bbb 20
A 1 aaa 10
But I want the sorting to happen on the new column that is added as well. A solution I could think of is to share a single sheet. But that doesn't serve my purpose so I need a linking which is sophisticated enough to sync across the books. Is there a pivot column based linking where the column1 in two books are taken as a reference when the manipulation happens on any sheet. Any help is appreciated.
I'm not sure why this isn't working for you, but I may be misinterpreting how you've set this up.
I've set up two workbooks, each with identical data for the first three columns, the fourth column in Book1 being linked to the same column in Book2.
Here, you can see the formula view after I sorted on Column A.
This will not work properly if you had previously enabled Auto Filter Before putting in the links, since the Auto Filter will not have extended the filter range by itself. To fix this particular issue, simply disable and re enable the Auto Filter (You should see the drop-down icon on Column D after that).
I've run into this type of "missorting" problem before. My solution was always to copy and paste the formulas in a different sheet as values.
Otherwise you could make column D dynamic through VLOOKUP and not reference hard cell numbers.

vba sum value in column except one

I have a matrix in microsoft reports. It looks:
Product | Sold
apple | 1000
melon | 200
banana | 500
orange | 2000
sum(without orange) | x
sum | 3700
How to write expression in vba to sum all values without orange? Number of rows with fruits can be different so i cant use static index to identify product
=sum(IIf(Fields!Product.Value<>"orange", Fields!Sold.Value, 0))