How can I substitute quotation marks in Excel with SUBSTITUTE formula?

徘徊边缘 提交于 2019-12-06 18:33:31

问题


I have worksheet where I need named ranges to correspond to the contents of another cell. The text in the cell is something like:

Partitions w Studs 16" oc

Named ranges cannot have spaces, or most importantly, special characters like ". So, the range is named the following:

PartitionswStuds16oc

To change the former into a reference to the latter in the worksheet, I can handle removing the spaces with the following formula:

=SUBSTITUTE(B1," ","")

I cannot, however, substitute the " because the double-quotation mark is used to specify text in the formula. Excel can't parse the following formula, as expected:

=SUBSTITUTE(SUBSTITUTE(B1," ",""),""","")

Any tips on how to get around this? I know I could change the text to say 16-in. instead of 16", but I want to keep it as my client requested if possible.


回答1:


"""" escapes a ":

=SUBSTITUTE(SUBSTITUTE(B1," ",""), """", "")



回答2:


Try using CHAR(34) as substitute for ":

=SUBSTITUTE(B1,CHAR(34),"")



回答3:


To use double qutoes within a quoted string, just double them. In your case, this results in four consecutive double quotes:

=SUBSTITUTE(B1,"""","")


来源:https://stackoverflow.com/questions/5695169/how-can-i-substitute-quotation-marks-in-excel-with-substitute-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!