繁体   English   中英

我收到错误6:溢出。 为什么?

[英]I am getting error 6: overflow. Why?

这是我程序中的函数。 在while循环中,我溢出了。 为什么? 我该如何解决?

Sub durationhours(ByVal sheetname As String, ByVal counter60M As Integer)

Dim j As Integer, matchcounter As Integer, k As Integer, runningtotal As Integer

j = 8: matchcounter = 0: runningtotal = 0

For counter = 7 To counter60M

    While Worksheets(sheetname).Cells(counter, 2) = Worksheets(sheetname).Cells(j, 2)
        j = j + 1
        matchcounter = matchcounter + 1
    Wend

    If IsEmpty(Worksheets(sheetname).Cells(j, 2)) Then j = j + 3

    For k = counter To (counter + matchcounter)
        runningtotal = runningtotal + Worksheets(sheetname).Cells(counter, 10)
        'here is where you do the calculations for the duration hours
    Next k

    Worksheets(sheetname).Cells(counter, 11) = runningtotal

    counter = j: j = j + 1: matchcounter = 0: runningtotal = 0


Next counter

您最有可能由于以下三个原因之一(或多个原因)而收到该错误:

1)你的While循环永不逃脱

2) counter60M是一个非常大的数字

3) matchcounter是一个非常大的数字

更改

Dim j As Integer, matchcounter As Integer, k As Integer, runningtotal As Integer

Dim j As Long, matchcounter As Long, k As Long, runningtotal As Long

那你应该没事的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM