如何检查Excel单元格值是否有空格... Excel 2007 [英] How to check that excel cell value has spaces... excel 2007
本文介绍了如何检查Excel单元格值是否有空格... Excel 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一些值的Excel文件.我需要检查单元格值是否包含空格.例如,有时用户会在单元格中写入一些值,但错误地在单元格中按Enter或Space.我想查看单元格值内部是否有空格... 请告诉我该怎么做.
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.
谢谢
推荐答案
比方说,我在单元格A1中键入"ABC"(ABC后跟一个空格).这些公式中的任何一个都可以帮助:
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))
对于VBA版本:
Function HasSpaces(rng As Excel.Range) As Boolean
HasSpaces = Not (Len(rng.Value) = Len(Trim$(rng.Value)))
End Function
样品用量:
Sub tst()
Debug.Print HasSpaces(Range("A1"))
End Sub
这篇关于如何检查Excel单元格值是否有空格... Excel 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文