VBA判断A列数值中1第一次出现的行号
可以使用VBA中的循环语句来判断A列数值中1第一次出现的行号。以下是一个示例代码:
Sub FindFirstOne()
Dim lastRow As Long
Dim i As Long
Dim firstOneRow As Long
' 获取A列的最后一行
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
' 初始化firstOneRow为0,表示未找到1
firstOneRow = 0
' 循环遍历A列的每一行
For i = 1 To lastRow
' 如果该行A列的值为1,则记录行号并退出循环
If Cells(i, "A").Value = 1 Then
firstOneRow = i
Exit For
End If
Next i
' 输出结果
If firstOneRow > 0 Then
MsgBox "第一次出现1的行号为:" & firstOneRow
Else
MsgBox "未找到1"
End If
End Sub
将上述代码复制到VBA编辑器中的模块中,并运行该宏,即可判断A列数值中1第一次出现的行号
原文地址: https://www.cveoy.top/t/topic/h1sW 著作权归作者所有。请勿转载和采集!