首页 > 解决方案 > 对多行重复代码

问题描述

我有下面的 VBA 代码,它适用于一行。我需要这个循环 100 行并为每一行做同样的工作。有人可以帮我这样做吗?

Sub IsEmptyRange()

Dim cell As Range

Dim bIsEmpty As Boolean

bIsEmpty = False

For Each cell In Range("A1:H1")

    If IsEmpty(cell) = True Then

        bIsEmpty = True

        Exit For

    End If

Next cell

If bIsEmpty = True Then

    '**PLACE CODE HERE**

    [I1].Value = "Empty Cells"

Else

    '**PLACE CODE HERE**

    [I1].Value = "Complete"

End If

End Sub

谢谢!!

标签: excelvbaloopsrepeat

解决方案


你可以尝试实现这个吗?

* = things added/changed (remove when you put in VBA)

*Dim lRow as Integer
*Dim i as Integer

*lRow = Cells(Rows.Count, 1).End(xlUp).Row

*For i = 1 to lRow
For Each cell In Range("A" & i & ":H" & i)

If IsEmpty(cell) = True Then

    bIsEmpty = True

    Exit For

End If

Next cell

If bIsEmpty = True Then

'**PLACE CODE HERE**

*[I & i].Value = "Empty Cells"

Else

'**PLACE CODE HERE**

*[I & i].Value = "Complete"

End If
*Next i

推荐阅读