excel 查找下一个非空行

ct2axkht  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(192)

我有一个问题,我想做一些简单的代码,检查值,然后会发现下一个没有空单元格。我试着这样做,但我有问题:

Sub test()
Dim ark1 As Worksheet, ark2 As Worksheet
Dim i As Long, j As Long, lastRow As Long, nextRow As Long, actCell As Long, actCell2 As Long
Set ark1 = Worksheets("Arkusz1")
Set ark1 = Worksheets("Arkusz2")

For i = 1 To 20
    If ark1.Cells(i, "A") = ark1.Cells(1, "B") Then
        ark1.Cells(i, 1).Select
        actCell = ActiveCell.Row
        MsgBox actCell
    End If
Next i

For i = actCell To 20
    ark1.Cells(i, "A").Select
        If IsEmpty(ActiveCell) Then
            Next i
            Else
            ark1.Cells(i, "A") = 1
        End If
 Next i
End Sub
dgtucam1

dgtucam11#

感谢JvdV我找到了解决方案,也许它会对某人有用:

Sub test()
Dim ark1 As Worksheet
Dim i As Long, j As Long, lastRow As Long, nextRow As Long, actCell As Long, actCell2 As Long
Set ark1 = Worksheets("Arkusz1")

For i = 1 To 20
    If ark1.Cells(i, "A") = ark1.Cells(1, "B") Then
        ark1.Cells(i, 1).Select
        actCell = ActiveCell.Row
        MsgBox actCell
    End If
Next i

' Next no empty cell
For i = actCell + 1 To 20
        If IsEmpty(ark1.Cells(i, "A")) Then
            Else
            ark1.Cells(i, 1).Select
            actCell2 = ActiveCell.Row
            MsgBox "The active cell is not empty   " & actCell2
            Exit For
        End If
 Next i
End Sub

相关问题