For循环在VBA中没有任何原因被跳过

问题: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循环在VBA中被无缘无故地跳过,但仍然无法解决这个问题。

如果rowCount ,根据你的澄清评论,是22那么你的For循环变成

For currentRow = 24 To 22

这显然是一个没有操作,因为没有办法24可以计算到22。如果你需要计数在最后的数字的方向 ,那么你可以使用像

 For currentRow = 24 To rowCount Step Iif(rowCount - 24 < 0, -1, +1) 

但是这真的是你想要做的? 此外,开始使用行types和列types的Longtypes,现在工作表中的行数超过了32767,并且在所有模块的顶部使用Option Explicit来避免恼人的自发variables创build。