vba 如何检查Cell上是否有Integer?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1881103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:05:37  来源:igfitidea点击:

How to check if Cell has Integer on it?

excelvbaexcel-vba

提问by Tom

How to check if a specific Column has Integer on each cell, and if it contains a string, Insert a blank cell to row in question.

如何检查特定列是否在每个单元格上都有整数,如果它包含一个字符串,插入一个空白单元格到有问题的行。

回答by Heinzi

Untested:

未经测试:

Dim row As Long
Dim col As Long

col = 4      ' Whatever column you want to check

For row = 1 To 100     ' How many rows you want to check
    If Not IsNumeric(Cells(row, col).Value) Then
        ' Do whatever you want to do in this case
    End If
Next row

If you clarify what you mean by "Insert a blank cell to row in question", I will try to update my solution.

如果您通过“将空白单元格插入有问题的行澄清您的意思,我将尝试更新我的解决方案。

回答by akuhn

You can check even check with a forumla that the column contains no none-numbers only

您甚至可以通过论坛检查该列是否仅包含非数字

=COUNTBLANK(AAA:AAA)-COUNTBLANK(B:B)=COUNT(B:B)

where I assume that column AAA:AAA is empty.

我假设列 AAA:AAA 是空的。

回答by Pierre44

A mix of the other answers for bigger data. It first checks if the colomn has none Numbers only and if not, checks where.

大数据的其他答案的混合。它首先检查colomn 是否只有数字,如果没有,则检查哪里。

Dim row As Long
Dim LastRow As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row   'if you want the colomn B

If Excel.WorksheetFunction.CountBlank(Range("AAA:AAA")) - Excel.WorksheetFunction.CountBlank(Range("B:B")) = Excel.WorksheetFunction.Count(Range("B:B")) Then
For row = 1 To LastRow     

    If Not IsNumeric(Range("B" & row).Value) Then
        ' Do whatever you want to do in this case
    End If
Next row
End if