How to check that excel cell value has spaces… excel 2007

人盡茶涼 提交于 2019-12-14 02:17:46

问题


I have an Excel file that contains some values. I need to check if a cell value contains spaces. For example, sometimes a user will write some values in the cell but mistakenly press Enter or Space in the cell. I want to see if the cell value has spaces inside... Please tell me how to do this.

Thanks


回答1:


Let's say I type "ABC " in cell A1 (ABC followed by a space). Either of these formulas should help:

=LEN(A1)=LEN(TRIM(A1))

=EXACT(A1,TRIM(A1))

For a VBA version:

Function HasSpaces(rng As Excel.Range) As Boolean
  HasSpaces = Not (Len(rng.Value) = Len(Trim$(rng.Value)))
End Function

Sample usage:

Sub tst()
  Debug.Print HasSpaces(Range("A1"))
End Sub


来源:https://stackoverflow.com/questions/8212637/how-to-check-that-excel-cell-value-has-spaces-excel-2007

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