問題:在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. –