Searching a letter within a range in excel - excel

I need an excel formula that searches within a range, a cell that contains a word with letter "W" and then multiply the number stored in the cell from the right of it by 2 and display the sum of all this multiplied values in another cell.
Example: Range A4:Y4; B4 contains word "Woo" and C4 contains number "3"; E4 contains word "Wood" and F4 contains number "5"... I need Z4 to contain C4*2+E4*2+...
Please help me with that.

Try this in Z4:
=SUM(SUM(OFFSET($A$4,,IF(IFERROR(FIND("W",$A$4:$Y$4),0)>0,COLUMN($A$4:$Y$4)))))
Hit CTRL + SHIFT + ENTER.
Make sure A4 is not a number (otherwise this formula counts the value of A4 times the number of cells that don't contain "W").
If you want to count cell as well that contain small w's, use SEARCH instead of FIND (SEARCH = case insensitive; FIND = case sensitive).
Keep in mind: OFFSET is a volatile function, i.e. if you have a large datasheet, this might slow down the work a bit.

Found it!
=SUM(IFERROR(2*(LEFT(A4:X4)="W")*B4:Y4,0))
Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself.

Related

How can I extract words from a cell separately in excel

I am very new to using formulas in excel and I am having some issues. I have four comma separated words in a cell. When I type the words into the cell, I then want to extract each word separately into another cell without the comma.
See screenshot below.
The formula for extracting the first word is working, however the formula for the other 3 words is not and is returning a value error. If there is nothing in cell C7 I don’t want any errors in the other cells either. I will provide the code I have for extracting each of the words, any help appreciated.
Code for extracting first word:
=IF(LEN(C7)=0,"",IF(ISERROR(LEFT($C$7,FIND(",",$C$7)-1)),C7,LEFT($C$7,FIND(",",$C$7)-1)))
Code for extracting second word:
=IF(ISERROR(FIND(",",C7)),"",MID(C7,FIND(",",C7)+1,FIND(",",C7,FIND(",",C7)+1)-FIND(",",C7)-1))
Code for extracting third word:
=MID(C7,FIND(",",C7,FIND(",",C7)+1)+1,FIND(",",C7,FIND(",", C7,FIND(",",C7)+1) +2)-FIND(",", C7,FIND(",",C7)+1)-1)
Code for extracting fourth word:
=RIGHT(C7,LEN(C7)-FIND(",",C7,LEN(E7)+LEN(F7)+LEN(G7)))
One word in cell
No words in cell
When I type in four words it separates them as shown in 3rd screenshot using the formulas above in each cell, which is working ok. However I think I need to edit the formula in F, G and H7 so that if there is one word in C7, it is populated in E7 and F G and H7 are empty(don't show error value either), if there are two words in C7, the first word is populated in E7 and second word in F7 and so on. Apologies if I am not explaining correctly. Also to note, the length of the words in C7 will be variable.
With TEXTSPLIT()(currently available to beta channel Office 365):
Put this in E7
=IFERROR(TRIM(TEXTSPLIT(C7,",")),C7&"")
And it will spill tp the right.
If you are using an older version on a PC:
Put this in E7 and copy over:
=IFERROR(INDEX(FILTERXML("<a><b>"&SUBSTITUTE($C7,",","</b><b>")&"</b></a>","//b"),COLUMN(A1)),"")
Use this User-Defined Function (UDF):
Function Take(invoer As String, index As Integer) As String
temp = Split(invoer, ",")
If UBound(temp) >= index - 1 Then
Take = temp(index - 1)
Else: Take = ""
End If
End Function
And use it as follows in the Excel sheet:

Extracting strings between specific characters in excel and separating them with a comma

Is there a way to extract multiple strings between specific characters in excel and separating them with a comma.
For example:
I am thankful for every help!
The following requires a version of Excel O365 that supports dynamic arrays and the LET function.
If I understand correctly you are looking for something like this.
This formula will list all the positions of all [ in the string using dynamic array functions.
=LET(x,$B$2,
y, SEQUENCE(LEN(x)),
raw, IF(MID(x,y,1)="[",y,""),
filtered, FILTER(raw,raw<>"",""),
filtered)
LET allows you to set names within a formula using parameter pairs. The first is the name; the second is the value of the name. The last parameter is the value returned. In this case, x is set to cell B2. y is set to the array listing the numbers from 1 to the length of x using the dynamic array function SEQUENCE. raw is a list that shows the value of y if that position is [, otherwise it is blank. filtered uses the FILTER function to remove all of the blank rows. filtered is the last argument of the LET function so that is what is returned. If this formula is entered into cell A4 then A4 will show 1, A5 will show 14 and A6 will show 28.
If you then enter a similar formula in B4 replacing [ with ] then the result is {7,21,35} in cells B4, B5 and B6.
Finally, in cell B2 you can enter =TEXTJOIN(", ",TRUE,MID(A2,A4#+1,B4#-A4#-1)). This will return the result you are looking for.
If you are unfamiliar with dynamic arrays, A4# indicates an entire dynamic array starting in cell A4. In this case, it is the same as A4:A6.
More information on Dynamic Arrays
More information on LET
You can't do it with only formulas in Excel 2007. You need VBA UDF then. With Excel O365 having dynamic formula access, this can be done like:
=TEXTJOIN(", ",TRUE,TRIM(LEFT(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,"]",REPT(" ",100)),"[","</s><s> ")&"</s></t>","//s[starts-with(., ' ')]"),100)))
Considering that you are using too old version of excel which lacks dynamic array functions and besides too many other useful functions, You may probably have to do a long workaround here.
First using substitute and len You have to find out number of such square parenthesis in each of the row. Thereafter you have to work out the formula of max of such numbers.
Do it like this
Assuming your text-values in A2 for a max of 4 occurrences enter the following formula in B2
=SUBSTITUTE(TRIM(REPLACE(LEFT(A2,FIND("]",A2&"]")-1),1,FIND("[",A2&"["),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",2),"]","#",2))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",2),"[","#",2)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",3),"]","#",3))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",3),"[","#",3)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",4),"]","#",4))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",4),"[","#",4)),"")), " ", ", ")
Let's say this is the text in A2
I have a text [123] and some more [4523] and also [552222] how to extract [22]?
This will create a output of 123,4523,552222,22 in B2
There is no "extraction" in your question, just removal. The formula below replaces the unwanted characters with "", thereby removing them. Please try it.
=SUBSTITUTE(SUBSTITUTE(A2,"[",""),"]","")

Dynamic reference to the above cell

In my Excel worksheet, every 25 rows or so (this number is subject to change), a cell in column C contains a progressive number, identifying a set. Right now, there is a simple formula, e.g. in Cell 34:
= C9 + 1
When The number of rows above C34 changes, the formula updates automatically. No issue with that.
I am now experimenting with a macro that inserts a set in between two existing sets; therefore another number that should fit in the progression, and the following numbers should adapt.
I thought that formulas should change, to find the first number above the current cell and add +1.
Trying a solution from this link, I came up with the following formula:
=LOOKUP("z";$C$9:OFFSET(INDIRECT(ADDRESS(ROW();COLUMN()));-1;0))+1
It seems however that it only searches for text, giving a #N/Awhen there is no text and a #VALUE! when there is text; if I do not add the +1, it works fine.
I also tried
=LOOKUP(2;1/(C$9:C9<>"");C:C)
As explained in the link but all I get is 0
How do I modify these formulas to give me the expected result?
Assuming than the number of the first set is in A1,
enter this formula
=INDEX(A:A,MATCH(1E+100,OFFSET(A$1,,,ROW()-1)))+1
in the counting cells (A5,A10, A16 in the example):
Then you can insert rows for a new inserted set, for example:
When ypu copy the same formula into C10,
the set numbers update accordingly:
And you can fill the text elements of the set:

How to add white spaces in a field of Excel which is equal to length of a longer word

I have a scenario where I want my Microsoft excel field to have the same length of the longest word in the column.
Basically lets say if I have:
ACBBASDBBADSAD
BADFDFDDF
So here I want to have the second word with less characters to have white spaces at its end to match the length of the first word.
=&" " this definitely helps but I am unable to achieve the above scenario
Consider this screenshot:
In column B the length of each cell of column A is established with the formula =len(A1) copied down.
Cell D2 has the range name MaximumLength and the formula =max(B:B).
With that in place, you can create the padded values with this formula in cell G1, copied down:
=A1&REPT("*",MaximumLength-LEN(A1))
If you don't want to use the helper column and helper cell, you can use this array formula instead:
=A2&REPT("*",MAX(LEN(A1:A15))-LEN(A2))
This formula must be confirmed with Ctrl-Shift-Enter. It is advisable to use defined ranges, not whole columns in array formulas, hence the range in LEN(A1:A15). Adjust as desired.
I've used the "*" character so it is visible. Replace it with a space " " in your scenario.
You can add this formula to count maximum characters and use on some cell, because you will need to press a command for it to work, so every cell can't contain this formula, let's say it is on Z1:
=MAX(LEN($A:$A))
Certify to press ctrl+shift+enter on the formula
Then you use this formula on your cells:=REPT(" ";Z1-LEN(A2))&A2
Edit: Sorry, anwsered late, teylyn is more complete.

How to enter information in one cell based on text in another cell

I would like to enter information in a cell based on the text contained in a different cell. Specifically, if a cell in column A contains text that includes "insurance," "retirement," or "401K," then I want to place an "x" in its respective cell in Column B. If not, then cell B1 should be empty. The text needs to be contained within the cell, but does not need to be the exact text. E.g., an "x" would still be placed in the column next to "life insurance" or "insurance," "whole life insurance," etc.
E.g.,
Column A Column B
Life Insurance x
Securities
Retirement x
I tried to use the following formula, but am getting an error message when I do so:
IF(OR(ISNUMBER(SEARCH("insurance",A1,"retirement",A1, "401K",A1)),"x", "")
Any thoughts?
This formula should help:
=IF(OR(ISNUMBER(FIND("Insurance",A1)),ISNUMBER(FIND("Retirement",A1)),ISNUMBER(FIND("401K",A1))),"x","")
EDIT:
I came up with an array formula that I like a little better. Hope this helps:
=IF(COUNT(MATCH({"*Insurance*","*Retirement*","*401K*"},A1,0))>0,"x","")
This will require pressing CTRL + SHIFT + ENTER instead of just ENTER after putting it in the cell because it's an array formula.

Resources