简体   繁体   English

如何检查Excel电子表格中的单元格是否包含数字

[英]How can I check if a cell in Excel spreadsheet contains number

I have a column of addresses and I have to find those which don't contain street numbers. 我有一列地址,我必须找到那些不包含街道号码的地址。 Unfortunately, addresses have been input by various users and they do not follow the same pattern so the street type, street name, suburb are in different order and I can't use functions like LEFT, RIGHT or MID to check if particular character is a number. 不幸的是,地址已被各种用户输入,并且它们不遵循相同的模式,因此街道类型,街道名称,郊区的顺序不同,我不能使用LEFT,RIGHT或MID等功能来检查特定字符是否是数。 The column looks like this: 该列如下所示:

    10 Willsons Drive, Manhattan
    Epping, 23 Wet Rd
    Longsdale St, Kingsbury
    11 Link Crt, Pakenham

Is there an Excel or VBA function that can tell me if cell / string contains numbers? 是否有Excel或VBA函数可以告诉我单元格/字符串是否包含数字?

Put this into a Module, then in your worksheet, may be a column next to it, put formula =HaveNumbers(A2) and check if you want it like that (True/False). 把它放到一个模块中,然后在你的工作表中,可能是它旁边的一列,放入formula =HaveNumbers(A2)并检查你是否想要它(True / False)。 You can change it to Return a String instead. 您可以将其更改为返回字符串。 This Returns TRUE / FALSE. 返回TRUE / FALSE。

Function HaveNumbers(oRng As Range) As Boolean
     Dim bHaveNumbers As Boolean, i As Long        
     bHaveNumbers = False
     For i = 1 To Len(oRng.Text)
         If IsNumeric(Mid(oRng.Text, i, 1)) Then
             bHaveNumbers = True
             Exit For
         End If
     Next
     HaveNumbers = bHaveNumbers
End Function

There isn't a single VBA function that will do what you want, but the following function should do the trick: 没有一个VBA函数可以执行您想要的操作,但以下函数应该可以解决问题:

Public Function ContainsNumbers(Inp As String) As Boolean
    Dim Strings() As String, Str As Variant
    Strings = Split(Inp, " ")
    For Each Str In Strings
        If IsNumeric(Str) Then
            ContainsNumbers = True
            Exit For
        End If
    Next
End Function

Then put something like =ContainsNumbers(A1) in a nearby cell. 然后在附近的单元格中添加类似=ContainsNumbers(A1)的内容。

Thanks Monty. 谢谢蒙蒂。 In my case, though, numbers were not always separated from words so I had to iterate over each character. 在我的情况下,数字并不总是与单词分开,所以我不得不迭代每个字符。 I used following: 我使用以下:

Function ContainsNumber(text As String)
 'checks if given cell contains number

For i = 1 To Len(text)
    If IsNumeric(Mid$(text, i, 1)) Then
        ContainsNumber = True
    Exit Function
End If
Next
ContainsNumber = False

End Function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查Excel中的单元格是否包含超过特定值的数字? - How can I check if a cell in Excel contains a number over a specific value? Excel:检查单元格是否包含文本字符串中的数字 - Excel: Check if cell contains number in text string 如何确定Excel中的单元格是包含数字/文本还是公式? - How can I find out if a cell in Excel contains a number/text or a formula? 如何检查 excel 单元格是否包含单词 - How to check if a excel cell contains a word 如何从 Sharepoint 文档库自动签出 Excel 电子表格、编辑电子表格并重新签入? - How can I automate the checkout of an excel spreadsheet from a sharepoint document library, edit the spreadsheet, and check it back in? 如何将单元格中的数字四舍五入到 Excel 中的特定数字 - How can I round up a number in cell to specific number in Excel 如何从包含按行分组的数据的电子表格在 Excel 中创建表 - How can I create a table in Excel from a spreadsheet that contains data that is grouped in rows 如何计算excel中包含文本/数字的行数 - how can I count number of rows that contains text/numbers in excel 如何在excel 2010电子表格中删除任何列中没有单元格注释的行 - How can I remove any row which has no cell comments in any column, in an excel 2010 spreadsheet 如何读取单元格的指定值并将文件从 excel 转换为电子表格? - How can i read a specified value of cell and convert a file from excel into spreadsheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM