问题:在For currentRow = 25 To rowCount
之后,for语句的其余部分不断跳过。For循环在VBA中没有任何原因被跳过
我有两个其他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,但仍然无法弄清楚这一点。
在'For'循环之前'rowCount'的值是多少? – Bathsheba
任何行计数应该是“长”而不是“整数”类型。您还应完全限定单元格:阅读[VBA最佳实践 - 永不假定工作表](http://stackoverflow.com/documentation/excel-vba/1107/vba-best-practices/9218/never-assume-the-worksheet #T = 201704280559226199101)。 –
我试过MsgBox rowCount,它显示22. –