VBA宏错误6溢出

时间:2017-08-18 15:35:48

标签: vba

所以我一直在读取溢出错误,并更新了我用来填充的所有整数。我仍然有一些错误的问题。我的excel宏是一个美化的副本,循环遍历两个表,将成本与匹配值结合起来。

Sub MoveActual()
'Speed up macro section
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim i As Long 'Row in FcstAll
Dim j As Long 'Row in GL - Actuals
Dim FcstAll As Worksheet
Dim GlActuals As Worksheet
Dim FailedCopy As Boolean

Set FcstAll = Sheets("Forecast ALL")
Set GlActuals = Sheets("GL - Actuals All")
j = 2 'Initialize the GL - Actuals Loop

Do While GlActuals.Cells(j, 2).Value <> "" 'Loop through GL

    i = 3 'initialize the Forecast All Loop
    FailedCopy = True 'initialize Copy Check

    Do While FcstAll.Cells(i, 2).Value <> "" 'Loop through Fcst

        'Find Match between Fcst and GL
        If ((GlActuals.Cells(j, 2).Value = FcstAll.Cells(i, 2).Value And _
             GlActuals.Cells(j, 3).Value = FcstAll.Cells(i, 3).Value) And _
             Not (GlActuals.Cells(j, 17).Value = "Found")) Then 

            'Copy over actual
            FcstAll.Range(FcstAll.Cells(i, 22), FcstAll.Cells(i, 33)).Value = _
             GlActuals.Range(GlActuals.Cells(j, 5), GlActuals.Cells(j, 16)).Value 
            FailedCopy = False
            GlActuals.Cells(j, 17).Value = "Found"

        End If
        i = i + 1    'incriment i to continue loop


    Loop

    If FailedCopy Then

        'Copy over Details
        FcstAll.Range(FcstAll.Cells(i, 1), FcstAll.Cells(i, 3)).Value = _
           GlActuals.Range(GlActuals.Cells(j, 1), GlActuals.Cells(j, 3)).Value 
        FcstAll.Cells(i, 4).Value = "GL - Actuals All"
        FcstAll.Range(FcstAll.Cells(i, 5), FcstAll.Cells(i, 22)).Value = 0
        'Copy over missing Finance Data
        FcstAll.Range(FcstAll.Cells(i, 22), FcstAll.Cells(i, 33)).Value = _
           GlActuals.Range(GlActuals.Cells(j, 5), GlActuals.Cells(j, 16)).Value 

    End If
    j = j + 1   'incriment j to continue loop

Loop

'Restart processes
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True


End Sub

在'找到Fcst和GL if语句之间的匹配期间i = 709和j = 464时代码中断。

任何第二只眼睛都会受到赞赏,我可能会错过一些我无法找到它的小东西。

0 个答案:

没有答案