I have an Excel sheet with columns template and template name, I have to fill the template name column with a partial string in template column:
Template Template Name
This is String
String line contains data
This is Int
Int line contain data
int: in the String data
string: in the int data
Int: is empty or no string
I tried the below formula but its giving different results:
=IF(ISNUMBER(SEARCH("string",A2)),"string",IF(ISNUMBER(SEARCH("int",A2)),"int",IF(ISNUMBER(SEARCH("int:",A2)),"int",IF(ISNUMBER(SEARCH("string:",A2)),"string"))))
Output given by the formula in B column:
Template Template Name
This is String String
String line contains data string
This is Int int
Int line contain data int
int: in the String data string #it must be 'int'
string: in the int data int #it must be 'string'
Int: is empty or no string string #it must be 'int'
Please let me know what has to be changed to get the desired output.
重新排列搜索顺序:如果首先搜索较长的字符串(带有':'),然后搜索没有':'的字符串,则结果应该正确。
=IF(ISNUMBER(SEARCH("string:",A2)),"string",IF(ISNUMBER(SEARCH("int:",A2)),"int",IF(ISNUMBER(SEARCH("int",A2)),"int",IF(ISNUMBER(SEARCH("string",A2)),"string"))))
edited : to make the code suitable for direct entry in the spreadsheet cell (I previuosly thought of a VBA macro)
if you want the first occurrence between "string" and "int", then use
=IF(IFERROR(SEARCH("int",RC1),10000)>IFERROR(SEARCH("string",RC1),10000),"String", "Int")"
should you handle the case where neither "string" nor "int" are in the string, then just advance a check over the occurrence of either one of them
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.