I have different class name in excel column in character form. I want to convert it to numerical form and add in column C
If B2==N, make it 1
If B2==O, make it 0
If B2==A, make it 2
If B2==~, make it 9
I have written the following excel formula. I have added my formula and error message in image. Can you correct me where I am making mistake
=IF(B2='N',1,if(b2='O',0,if(b2='A',2,if(b2='~',9))))
Update
After adding the formula as per details answer
Personally I would do something like this, using IFS function:
=IFS(B2="N",1,B2="O",0,B2="A",2,B2="~",9)
Within Excel formulas, double quotes are used to denote the start and end of a text string. Numeric should not be within double quotes.
That said, we can use a formula like IF function but we can also avoid using double quotes by creating a table of reference, refer the image below, for alternative solutions - 7 APPROACHES
• Formula used in cell C2
=VLOOKUP($B2,$I$2:$J$5,2,1)
Without Table Of Reference the above formula can be written as
=VLOOKUP($B2,{"~",9;"A",2;"N",1;"O",0},2,1)
• Formula used in cell D2
=LOOKUP($B2,$I$2:$J$5)
Without Table Of Reference the above formula can be written as
=LOOKUP($B2,{"~",9;"A",2;"N",1;"O",0})
• Formula used in cell E2 --> "Correction To Your Own Formula"
=IF(B2="N",1,IF(B2="O",0,IF(B2="A",2,IF(B2="~",9))))
• Formula used in cell F2
=IFS(B2="~",9,B2="A",2,B2="N",1,B2="O",0)
• Formula used in cell G2
=SWITCH($B2,"~",9,"A",2,"N",1,"O",0)
Note the formulas used in cell F2 & G2 you need to have either Excel 2019, Excel 2021 Or O365 hence its better to use a Table Of Reference to avoid using Double Quotes.
So, if there is a space before each characters then the formula, shall change refer the image below and & the formulas,
• Formula used in cell C2
=VLOOKUP(TRIM($B2),$I$2:$J$5,2,1)
• Formula used in cell D2
=LOOKUP(TRIM($B2),$I$2:$J$5)
• Formula used in cell E2
=IF(TRIM($B2)="N",1,IF(TRIM($B2)="O",0,IF(TRIM($B2)="A",2,IF(TRIM($B2)="~",9))))
• Formula used in cell F2
=IFS(TRIM($B2)="~",9,TRIM($B2)="A",2,TRIM($B2)="N",1,TRIM($B2)="O",0)
• Formula used in cell G2
=SWITCH(TRIM($B2),"~",9,"A",2,"N",1,"O",0)
And if those are not spaces and actually are non printable characters then just change the TRIM to SUBSTITUTE Function
C2
=VLOOKUP(SUBSTITUTE($B2,CHAR(160),""),$I$2:$J$5,2,1)
D2
=LOOKUP(SUBSTITUTE($B2,CHAR(160),""),$I$2:$J$5)
E2
=IF(SUBSTITUTE($B2,CHAR(160),"")="N",1,IF(SUBSTITUTE($B2,CHAR(160),"")="O",0,IF(SUBSTITUTE($B2,CHAR(160),"")="A",2,IF(SUBSTITUTE($B2,CHAR(160),"")="~",9))))
F2
=IFS(SUBSTITUTE($B2,CHAR(160),"")="~",9,SUBSTITUTE($B2,CHAR(160),"")="A",2,SUBSTITUTE($B2,CHAR(160),"")="N",1,SUBSTITUTE($B2,CHAR(160),"")="O",0)
G2
=SWITCH(SUBSTITUTE($B2,CHAR(160),""),"~",9,"A",2,"N",1,"O",0)
In Excel, double quotes is used to enclose character values not single quote. Hence, your formula will become
=IF(B2="N",1,IF(B2="O",0,IF(B2="A",2,IF(B2="~",9,""))))
Additionally, I have added an else clause with blanks in last IF.
Also, if you are on newer versions of Excel, then you can also use SWITCH which is easier and shorter
=SWITCH(B2,"N",1,"O",0,"A",2,"~",9,"")
For example, if I have this,
Then I want to stack them in one cell.
Of course, I have hundreds of rows so I want to do it automatically. How can I achieve this? I know transpose, but that doesn't seem to do this.
If by 'stack' you mean one above the other, try entering =A1 & CHAR(10) & B1 in cell C1.
You might need to check the "Wrap text" in the cell formatting. For that, click-right on the cell, and in the appearing window, check this checkbox:
For small dataset you can manually concatenate cell like =A1 & Char(10) & B1 but for large dataset you can use TEXTJOIN() function like below
=TEXTJOIN(CHAR(10),TRUE,A1:B1)
You must turn on WRAP TEXT for result cell to display line by line. Please note TEXTJOIN() is available on Office-2019 or higher. For older version you need UDF of textjoin.
I am trying to write a formula to create an abbreviation of a text that contains more than two spaces in a excel cell using a formula that will trim the first word of every string after space and put it as a string like the example given below.
Example : Global Remote Access Management System - GRAMS
Formula :
=IF(OR(LEN(K7)>10,((LEN(K7)-LEN(SUBSTITUTE(K7," ","")))>2),CONCATENATE((LEFT(K7),3),RIGHT(K7,3)),K2))
I am not sure why it's not working. I tried to trouble individually and it works but as a formula, it fails.
Any help will be greatly appreciated. Thank you in advance.
If you have Excel 365 or Excel 2019 or Excel Web then following formula shall work for you.
=TEXTJOIN("",TRUE,MID(TRIM(MID(SUBSTITUTE(" "&A1," ",REPT(" ",99)),ROW($A$1:$A$10)*99,99)),1,1))
Notes:
Above formula will work for 10 words. If there are more then change ROW($A$1:$A$10) part to suit. It assumes your data is in cell A1.
This is an array formula and therefore needs to be committed by CTRL+SHIFT+ENTER simultaneously. If done correctly then Excel will wrap it with {} braces automatically.
In later versions of Excel with the CONCAT function, you can use:
=CONCAT(LEFT(FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s")))
If you want to not abbreviate phrases with only a single space, you can test for that with an IF.
Algorithm
Create an XML out of the string with the nodes being each space separated substring
Concatenate the first letter of each node
The above formula will work with any number of words.
If you have an earlier version of Excel, without the necessary functions for the above formula, you can either use VBA, or you can use a variation of the following formula:
seq_99 is a Named Formula referring to:
=IF(ROW($A$1:INDEX($A:$A,255,1))=1,1,1*(ROW($A$1:INDEX($A:$A,255,1))-1)*99)
and then, the main formula:
=INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),1,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),2,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),3,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),4,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),5,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),6,1) &
INDEX(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99))),7,1)
Note that each line represents a letter, and you will need as many lines as there are possible words in the string. (You can have more lines, as those that don't match will merely add a null string to the string, which is nothing).
If I manually reference a cell in another spreadsheet (by typing = in the destination cell and then clicking in the source spreadsheet), excel creates a formula like this: ='H:\excel\data\[source_file.xls]Sheet1'!$C$5
I am wanting to create that formula from the cell and path which are stored in cells in the destination spreadsheet (and some strings).
So I have in 3 cells B1:B3 in the destination spreadsheet these strings:
H:\excel\data\
source_file.xls
Sheet1!$c$5
Then, so far, I have placed this formula in the cell where I want the data from the source spreadsheet:
=B1&"["&B2&"]"&B3
Which evaluates to:
H:\excel\data\[source_file.xls]Sheet1!$c$5
Pretty close to what I need. But as you can see some single quotes are missing. If I try to put these in, excel seems to think I am giving it a defined name.
Is there perhaps some sort of escape character I should put before the quote to make it work?
I have searched this website and excel help files to no avail.
That is the end of the question but I anticipate that someone is going to ask me why I am doing this. Well I want to automatically pluck values from a directory full of spreadsheets (which all have the same format)the value of one cell from each.
I had tried to do it using the advice found here:
http://www.ashishmathur.com/extract-data-from-multiple-cells-of-closed-excel-files/
Unfortunately, I was only able to get the first step to work (create a list of filenames of the files in the source directory). The remaining steps are not possible because my employer does not allow downloading of add-ins for security reasons (it is a hospital).
So I thought the approach outlines above might work but I can't quite make it happen!
Thanks
Mike A
Use INDIRECT()
=INDIRECT("'" & B1 & "[" & B2 & "]" & B3)
As stated in the comments the ' would need to added to B3, so the input is Sheet1'!$C$5.
You may want to split the sheet name from the cell address then you could do:
=INDIRECT("'" & B1 & "[" & B2 & "]" & B3 & "'!" & B4)
Where B3 is only the sheet name and B4 the cell address.
I am using MAC 2011 Excel (version 14.4.2)
When I input a function =IF(B5=B6,B5, " ")
but when i press enter, instead of giving me the result, the cell show
=IF(B5=B6,B5, " ")
What am I mising?
If you mean that your cells are showing formulas instead of the values produced by the formulas you can find an option in the Formulas tab to turn this off/on. I'm on PC where is looks like the following:
Obviously it will differ slightly on a Mac OS.
When I usually see this, the cell is formatted as Text.
Clear all formats from the cell
Force Excel to look at cell contents again by either
a. Find-Replacing all "=" with "=" or
b. Entering cell editing and immediately leaving
source