Closed. This question needs
details or clarity。它当前不接受答案。
想改善这个问题吗?添加详细信息,并通过
editing this post阐明问题。
5年前关闭。
Improve this question
我确实需要这个项目的帮助,但似乎无法摆脱这个错误。有人可以推荐解决方案吗?
Sub Dsurvey()
Dim i As Integer
Dim j As Integer
Dim k As Integer
k = 3
For i = 3 To 22
j = j + 1
If Sheets("2").Cells(j, "A").Value - Sheets("2").Cells(i, "A").Value = Sheets("2").Cells(j, "B").Value - Sheets("2").Cells(i, "B").Value Then
Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(i, "A").Value
Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(i, "B").Value
Do While Sheets("2").Cells(k, "J").Value <= Sheets("2").Cells(j, "A").Value
Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(k - 1, "J").Value + 100
Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(k - 1, "K").Value + 100
k = k + 1
End If
Next i
End Sub
并不是说您缺少End If
,而是您没有用Do While
关闭Loop
。
k = 3
For i = 3 To 22
j = j + 1
If Sheets("2").Cells(j, "A").Value - Sheets("2").Cells(i, "A").Value = Sheets("2").Cells(j, "B").Value - Sheets("2").Cells(i, "B").Value Then
Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(i, "A").Value
Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(i, "B").Value
Do While Sheets("2").Cells(k, "J").Value <= Sheets("2").Cells(j, "A").Value
Sheets("2").Cells(k, "J").Value = Sheets("2").Cells(k - 1, "J").Value + 100
Sheets("2").Cells(k, "K").Value = Sheets("2").Cells(k - 1, "K").Value + 100
k = k + 1
Loop
End If
Next i
调试版本:k = 3
With Sheets("2")
For i = 3 To 22
j = j + 1
If IsNumeric(.Cells(j, "A")) And IsNumeric(.Cells(i, "A")) And IsNumeric(.Cells(j, "B")) And IsNumeric(.Cells(i, "B")) Then
If .Cells(j, "A").Value - .Cells(i, "A").Value = .Cells(j, "B").Value - .Cells(i, "B").Value Then
.Cells(k, "J").Value = .Cells(i, "A").Value
.Cells(k, "K").Value = .Cells(i, "B").Value
Do While .Cells(k, "J").Value <= .Cells(j, "A").Value
.Cells(k, "J").Value = .Cells(k - 1, "J").Value + 100
.Cells(k, "K").Value = .Cells(k - 1, "K").Value + 100
k = k + 1
Loop
End If
Else
Debug.Print "Not numeric: & " & i & Chr(45) & j & Chr(45) & k
End If
Next i
End With