【发布时间】:2017-05-03 06:50:41
【问题描述】:
问题:在For currentRow = 25 To rowCount 之后,for 语句的其余部分不断被无缘无故地跳过。
我在这个有问题的代码块之前还有另外两个 For 语句,它们的格式与这个相同,并且都可以正常工作。
Public Sub WeightB()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
sourceCol = 7
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
For currentRow = 24 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
Exit For
End If
Next
End Sub
我已经推荐了For loops being skipped without cause in VBA,但仍然无法解决这个问题。
【问题讨论】:
-
rowCount在For循环之前的值是多少? -
我试过 MsgBox rowCount 显示 22。
-
@Peh 但是为什么前两个语句有效?这对我来说很奇怪。非常感谢您的建议!