在列中搜索大于 1 的值 Excel VBA



>有人知道如何在列中查找大于 1 的值吗?

Set fileSheet = wb.ActiveSheet
fileSheet.Name = "Test"

Set rng = fileSheet.Range("D:D")
Set rngFound = rng.Find(">1")
If rngFound Is Nothing Then
MsgBox "No value"
End If

我正在尝试这样做,但我知道如果您放置双 qoute,它将被视为字符串,那么有什么方法可以在过滤之前查找大于 1 的值?请注意,我将使用包含数千个数据的列。

假设单元格包含数字而不是公式,这应该会加快速度。数组会快得多,但取决于您到底要实现什么。

Sub x()
Dim r As Range, filesheet As Worksheet, Rng As Range
Set filesheet = wb.ActiveSheet
filesheet.Name = "Test"
Set Rng = filesheet.Range("D1", filesheet.Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants, xlNumbers)
For Each r In Rng
If r.Value > 1 Then
'do whatever
End If
Next r
End Sub

像这样使用两个用于最后一列和最后一行的索引的循环。 或者,使用活动工作表区域的每个周期。 更多信息: 如何循环访问 Excel VBA 或 VSTO 2005 中的所有单元格

显示范围D1 到 D100> 1 的单元格

Dim i As Integer
With ThisWorkbook.Sheets(1)
For i = 1 To 100
If .Cells(i,4).Value > 1 Then
MsgBox "Value Found! Cell D " & i
End If
Next i
End With

最新更新