我对此感到疯狂。我在我的一个excel vba模块中有一个基本代码块,它可以提前终止,并且在使用断行时,我发现所有内部值都被重置为0.
我的目标:
这是基本的jist。我在块中有一些保护措施,如果所有高于当前值的值都小于它,一旦for循环循环到最后,等等。
运行我的代码后,diff_value,upcol和upcol_maxflag都是0,神秘。 p是51.
代码和变量定义如下:
upcol - up列计数器;如果上面的单元格值不大,则会增加 filled_col - 单元格地址的字符串数组 filled_collen - filled_col数组的长度(它是一维数组) upcol_maxflag - 用于在经过当前的所有单元格之后 索引单元格,没有一个更大,因此它会突破 循环下一个索引
Excel VBA代码(Excel 2013):
Dim p As Integer
Dim diff_value As Double
Dim upcol As Integer
Dim upcol_maxflag As Integer
For p = (filled_collen - 1) To 1
diff_value = 1
upcol = 1
upcol_maxflag = 0
Do While diff_value > 0
diff_value = Range(filled_col(p)).Value - _
Range(filled_col(p - upcol)).Value
If Val((Range(filled_col(p)).Value) > _
Val(Range(filled_col(p - upcol)).Value)) Then
upcol = upcol + 1
End If
If (upcol = p) And (p <> 1) Then
upcol_maxflag = 1
Exit Do
End If
Loop
If (upcol_maxflag <> 1) Then
Range(filled_col(p)).Value = Range(filled_col(p)).Value _
+ Range(filled_col(p - upcol)).Value
End If
Next
感谢任何能够弄清楚这里发生了什么的人。我觉得我对excel VBA有一个很好的掌握,但这是踢我的屁股。