I'm using VBA in Excel to try and write some macros, however, I am very new to the process.
我在Excel中使用VBA尝试编写一些宏,但是,我对这个过程很新。
At the moment, I am trying to use a for loop to search a column for a non-numeric value. To do this I wrote the following:
目前,我正在尝试使用for循环来搜索列中的非数字值。为此,我写了以下内容:
rwcnt = WorksheetFunction.CountA(Range("A:A"))
Dim i As Integer
For i = 1 To rwcnt
If Cells(i, 1).Value = Not IsNumeric Then
Cells(i, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Exit For
End If
This is returning an error saying that the argument is not optional and it highlights IsNumeric.
这返回一个错误,说该参数不是可选的,它突出显示IsNumeric。
What I'd like to accomplish is to search column A and select the first cell that contains non-numeric characters in it outside of my headers. Also, this is searching through >100K cells so if there is a less intensive way to do this process, suggestions would also be nice.
我想要完成的是搜索A列并在我的标题之外选择包含非数字字符的第一个单元格。此外,这是搜索> 100K单元格,所以如果有一个不太密集的方式来做这个过程,建议也会很好。
Any help would be appreciated and again, I don't know much at all about this stuff so if everything is wrong, feel free to say so.
任何帮助将不胜感激,我再也不知道这些东西,所以如果一切都错了,请随意说。
2 个解决方案
#1
4
The below code should work fine, note how I have used IsNumeric
下面的代码应该可以正常工作,请注意我是如何使用IsNumeric的
Sub t()
rwcnt = WorksheetFunction.CountA(Range("A:A"))
Dim i As Integer
For i = 1 To rwcnt
If Not (IsNumeric(Cells(i, 1).Value)) Then
range(Cells(i, 1).address, Cells(i, 1).End(xlDown).address).Select
Exit For
End If
Next
End Sub
Also you dont need all of them select's, the above achieves the same result
此外,你不需要所有选择,上面达到了相同的结果
#2
2
IsNumeric()
is a function to test an expression, so it should be used like this :
IsNumeric()是一个测试表达式的函数,因此它应该像这样使用:
rwcnt = WorksheetFunction.CountA(Range("A:A"))
Dim i As Integer
For i = 1 To rwcnt
If IsNumeric(Cells(i, 1).Value) <> True Then
Cells(i, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Exit For
End If
Next i
When in VBA Editor, press F2 to see Object Browser to get info on functions and press F1 to open Help on that specific function! ;)
在VBA编辑器中,按F2查看对象浏览器以获取有关功能的信息,然后按F1打开该特定功能的帮助! ;)
#1
4
The below code should work fine, note how I have used IsNumeric
下面的代码应该可以正常工作,请注意我是如何使用IsNumeric的
Sub t()
rwcnt = WorksheetFunction.CountA(Range("A:A"))
Dim i As Integer
For i = 1 To rwcnt
If Not (IsNumeric(Cells(i, 1).Value)) Then
range(Cells(i, 1).address, Cells(i, 1).End(xlDown).address).Select
Exit For
End If
Next
End Sub
Also you dont need all of them select's, the above achieves the same result
此外,你不需要所有选择,上面达到了相同的结果
#2
2
IsNumeric()
is a function to test an expression, so it should be used like this :
IsNumeric()是一个测试表达式的函数,因此它应该像这样使用:
rwcnt = WorksheetFunction.CountA(Range("A:A"))
Dim i As Integer
For i = 1 To rwcnt
If IsNumeric(Cells(i, 1).Value) <> True Then
Cells(i, 1).Select
Range(Selection, Selection.End(xlDown)).Select
Exit For
End If
Next i
When in VBA Editor, press F2 to see Object Browser to get info on functions and press F1 to open Help on that specific function! ;)
在VBA编辑器中,按F2查看对象浏览器以获取有关功能的信息,然后按F1打开该特定功能的帮助! ;)