Cell variable inside COUNTIF - variables

I have a column with many words in each cell. I want to count how many times a word is in the column and use:
=COUNTIF(Data!C3:C9,"*word*")
It works fine, now I want to reference a cell instead put the word. I am trying this, but it doesn't work:
=COUNTIF(Data!C3:C9,"*"+A3+"*")
How can I use the cell variable inside the criterion?

In Google Spreadsheet, to concatenate two or more strings use ampersand, that is: "&"
Try the following formula:
=COUNTIF(Data!C3:C9,"*"&A3&"*")
Or you can alternatively try:
=COUNTIF(Data!C3:C9,CONCATENATE("*",A3,"*"))

Related

Use the same formula multiple times for multiple cells containing dropdown lists

My file looks something like this
image
An IF statement would be too long considering I have 20 different long formulas.
Update: I later tried to use an IF statement but failed because it depended on substitute function to replace cell references in the equation but substitute returned a string which coudn't be used as a function by IF.
User should be able to increase available rows by simply copy and insert the previous row.
I can use index match to copy a cell's value which contain the right formula according to the dropdown list but when the user select the same item again I can't update the formula with the new values without affecting the previous cell which used the same formula.I couldn't find a way to copy the same formula several times and replace cell references in it (without human interaction like search and replace) i.e. by using Substitute function which couldn't replace cell references as it looks through the cell's value not it's formula (the cell which contain the main formula).Here is one of the 20 formulas I have
=(Tables!O167*144/(Tables!O158*Tables!O159)/4005)^2*INDEX(Tables!A159:L200;MATCH(INDEX(Tables!A159:A200;MATCH(TRUE;INDEX(Tables!A159:A200>=Tables!O158*Tables!O159/(Tables!O160*Tables!O161);0);));Tables!A159:A200;0)+MATCH(INDEX(Tables!B159:B200;MATCH(INDEX(Tables!A159:A200;MATCH(TRUE;INDEX(Tables!A159:A200>=Tables!O158*Tables!O159/(Tables!O160*Tables!O161);0);));Tables!A159:A200;0)+MATCH(INDEX(Tables!B159:B200;MATCH(TRUE;INDEX(Tables!B159:B200>=Tables!O164/(2*Tables!O158*Tables!O159/(Tables!O158+Tables!O159));0);));Tables!B159:B200;0)-1;);Tables!B159:B200;0)-1;MATCH((INDEX(Tables!C158:L158;MATCH(TRUE;INDEX(Tables!C158:L158>=Tables!O163;0);)));Tables!A158:L158;0))I tried to use FORMULATEXT to convert the formula into a string then use substitute to replace the cell references then use the depreciated Evaluation function but hit the 255 char limit. I searched a lot on google but to no avail, I don't mind a VBA code but a macro free method would be better, Thanks.
TL;DR: Is there a way to copy a formula stored in a cell and replace some of the cell references then enter it in another cell multiple times with different cell references each time ??
Try this in E2 and fill down.
=CHOOSE(MATCH(LOWER(LEFT(A2)), {"r","s","t"}, 0), B2*C2, B2^2, B2*C2/2)

VBA script in excel to find and highlight text

I am looking for a VBA script that will help me find certain keywords in a cell and if found highlight the entire row. Below are my requirements:
I have a database of words eg hell, get out, shut up, don't you dare etc. I need a macro to search the data in column "E" of excel and in case any of the cell in column "E" contains any word listed in the database (irrespective of the case of the word upper or lower)the entire row is highlighted. The word can be in the beginning, middle or end of the cell and the macro should be able to find that word and highlight the column.
Seeking help from all VBA masters for this.
You can do this with conditional formatting, instead of VBA.
Conditional formatting works by applying a 'second formula' to a given cell. If the 'second formula' results in TRUE, then special formatting conditions can be applied.
EXAMPLE CONDITIONAL FORMATTING
For example, if you have a single column of Data, A:A, and you want to check if that column has the exact string "hello world", you could add a conditional format [Home ribbon, Styles section, Conditional Formatting] that turns a cell yellow with this formula:
=$A1="hello world"
This will only result in TRUE if the cell in column A at that row equals exactly "hello world" [note that Column A has an absolute-reference $, and row 1 does not, so row 1 is relative to the position of the cell in the condiitonal format rule].
To check to see if any row in column A includes hellow world, we need to add a SEARCH function, which checks to see if a small search string is inside of a larger string:
=SEARCH("hello world",$A1)>0
Because SEARCH by default returns the first character in a larger string that matches the search term (and if it finds nothing, it returns #N/A), we check to see if our search for "hello world" in column A returns a number.
SEARCHING MULTIPLE COLUMNS
Now, to see if ANY column, say from A-D, includes "hello world", we concatenate each value of each column so that it gives us a single string, which we can search through for "hello world", like so:
=SEARCH("hello world",$A1&$B1&$C1&$D1)>0
This will first create a single string, equal to A1 & B1 & C1 & D1 all in a row. Then it will search that newly created string to see if "hello world" is inside it, and return a number value if it is.
ARRAY FORMULA BASICS
Finally, we need to do the tricky part - searching for multiple terms instead of just "hello world". This is called an Array Formula. An array formula works by performing a single operation on multiple cells, and then returning multiple results in an Array. In an Excel sheet, an array formula must be confirmed with CTRL + SHIFT + ENTER (instead of just ENTER), but in conditional formatting, you actually don't need to do anything special - it will recognize an array formula without a special command.
As an example of conditional formatting, see this example, which checks whether any value from A1:A5 = 10, and if it does, it gives us the value in B1:B5:
=IF(A1:A5=10,B1:B5,"")
Remember in Excel on a worksheet, this would be confirmed by pressing CTRL + SHIFT + ENTER. If you do test this, it will give you the following result, assuming A2 = 10 and A5 = 10:
={"";B2;"";"";B5}
This result would actually be hidden, because Excel can't "collapse" an array function on its own. So assume column B had values, and we actually want to sum them together. We would then wrap the Array formula in a SUM function:
=SUM(IF(A1:A5=10,B1:B5,""))
As you can see if you test this, we have actually created our own SUMIF function, using Array formulas instead of the built-in SUMIF.
SEARCHING FOR MULTIPLE TERMS WITH ARRAY FORMULAS
So now we apply these principles to the conditional formatting, to create an array formula which will check our concatenated 'NEW STRING' for any number of provided terms, as follow [Assumes the search terms are typed into cells E1:E10]:
=SUM(SEARCH($E$1:$E$10,$A1&$B1&$C1&$D1)>0)
This formula can be placed as a conditional formatting rule which reaches all of A:D. Set the rule to highlight / change format in whatever way you like.

Spreadsheetlight Formula not working

i'm using Spreadsheetlight for creating excel document. I need to use a formula on a specific cell, but it's not working. The code:
report.SetCellValue(string.Format("{0}{1}", Report.CELL_MAP.ACTIVITY_CRU_COL, row), string.Format("=IF({0}{1}=0; 0; ROUND(({2}{1}/{0}{1})*100; 0))", Report.CELL_MAP.ACTIVITY_REAL_MD_VAL_COL, row, Report.CELL_MAP.ACTIVITY_INVOICED_MD_VAL_COL));
Is there something I'm missing? Setting formulas like '=E9' is stored in cell as formula and works in final document. Any ideas why it doesn't work?
Should it be commas instead of semicolons in the formula? Like so:
report.SetCellValue(string.Format("{0}{1}", Report.CELL_MAP.ACTIVITY_CRU_COL, row), string.Format("=IF({0}{1}=0, 0, ROUND(({2}{1}/{0}{1})*100, 0))", Report.CELL_MAP.ACTIVITY_REAL_MD_VAL_COL, row, Report.CELL_MAP.ACTIVITY_INVOICED_MD_VAL_COL));
I have just tested Vincent's answer on SUMPRODUCT and IF formulas and I can confirm that it works.
SUMPRODUCT example:
Instead of
sl.SetCellValue(cellRef, "=SUMPRODUCT(A2:B2;--A1:B1=\"Something\")");
should be
sl.SetCellValue(cellRef, "=SUMPRODUCT(A2:B2,--A1:B1=\"Something\")");
IF example:
Instead of
sl.SetCellValue(cellRef, "=IF(A1=\"Something\";1;0)");
should be
sl.SetCellValue(cellRef, "=IF(A1=\"Something\",1,0)");

CONCATENATE formulas

I have used the following formula to combine text strings into a new cell and am getting FALSE in my result cell.
=CONCATENATE(LEFT(D2,3),A2)
I am trying to create a unique reference number combining the first three characters of a client name to an entry number.
The formula box shows me the correct answer but is displays as FALSE in my result cell and I don't know how to correct it.
try the following formula instead:
=MID(D2,1,3) & A2

Format row if one or more cells contain a specified string

In excel 2007, I would like to apply a formatting rule throughout my entire workbook, which will format a row if and only if that row contains one or more cells with a question mark. I'm trying this formula:
=IF(countif(c2:l2, "?")>0)
Where row 1 contains a header, and the values that I would like to check should range from columns C to L. Excel says that there is an error however, can anyone see what that error is?
The problem is that "?" is a wildcard. You need to escape it with a tilde:
=COUNTIF($C2:$L2, "~?")>0
Also, you didn't have absolute referencing for the columns. Also, you don't need IF in a conditional format. The "condition" is the IF.