我的第一篇文章在这里。你们帮助了我上百万次,但是这次我没有设法在Google或这里找到答案。
我创建了2个for循环,一个在Excel中另一个在其中,此处是缩短的版本:
For r = 3 To 25
For col = rota_current_col To 100
Debug.Print "Current position:" & r & "," & col // + some code later
Next col
//some code
Next r
第一个循环根本不起作用。我没有在循环内的代码中触摸任何这些值(r,col)。此调试打印结果显示的值为从3.7到3,100的值,但没有循环到“ r”值。
我希望这很清楚,在此先感谢您!
编辑1:按要求进行完整循环:
For r = 3 To 25 ' NOT WORKING :(
For col = rota_current_col To 100
Debug.Print "Current position:" & r & "," & col & " current Rota position: " & rota_current_row & "," & rota_current_col & " current Comp position: " & comp_current_row & "," & comp_current_col
Select Case Cells(rota_current_row, rota_current_col)
Case "U", "UZ", "U1", "UZ1"
If Cells(rota_current_row, rota_current_col) <> Cells(comp_current_row, comp_current_col) Then
result.Cells(current, 1) = rota.Cells(rota_current_row, 1)
result.Cells(current, 2) = rota.Cells(rota_current_row, 2)
result.Cells(current, 3) = rota.Cells(rota_current_row, 3)
result.Cells(current, 4) = rota.Cells(rota_current_row, rota_current_col)
result.Cells(current, 5) = rota.Cells(rota_current_row, rota_current_col).Address
result.Cells(current, 6) = comp.Cells(comp_current_row, comp_current_col)
result.Cells(current, 7) = comp.Cells(comp_current_row, comp_current_col).Address
current = current + 1
End If
End Select
rota_current_col = rota_current_col + 1
comp_current_col = comp_current_col + 1
Next col
rota_current_row = rota_current_row + 1
comp_current_row = comp_current_row + 1
Next r
您要我粘贴完整的代码吗?
答案 0 :(得分:0)
在col = 100之前,r不会变为4。内循环需要完成,然后外循环开始。
尝试
Sub yo()
r = 3
For col = rota_current_col To 100
Debug.Print "Current position:" & r & "," & col
r = r + 1
If r = 26 Then Exit Sub
Next col
End Sub