Что является причиной ошибки этого индекса за пределами диапазона? - PullRequest
0 голосов
/ 05 октября 2018

У меня есть массив, который заполняется в шаблон, ячейка назначения A3 (первые две строки - заголовки).Массив заполняет первую строку сотрудника, но затем я получаю subscript out of range error после заполнения первой строки массива в этой строке:

 Dest.Offset(destcol, destrow) = Data(sourcerow, sourcecol)

остаток скрипта для справки:

Option Explicit

Sub Main()

    Dim Wb As Workbook
    Dim Data, Last, Login
    Dim sourcerow As Long, sourcecol As Long, destrow As Long, destcol As Long
    Dim Dest As Range


    'Refer to the template
    Set Wb = Workbooks("Default_Changes_Template.xlsx")

    'Refer to the destination cell
    Set Dest = Wb.Sheets("Sheet1").Range("A3")

    'Read in all data
    With ThisWorkbook.Sheets("Full Population")
        Data = .Range("AL3", .Range("A" & Rows.Count).End(xlUp))
    End With

    Wb.Activate
    Application.ScreenUpdating = False

    'Process the data
    For sourcerow = 1 To UBound(Data)
        'Manager changes?
        If Data(sourcerow, 1) <> Last Then
            'Skip the first
            If sourcerow > 1 Then
                'Scroll into the view
                Dest.Select
                'Save a copy
                Wb.SaveCopyAs ThisWorkbook.Path & Application.PathSeparator & _
                              ValidFileName(Login & " - " & Last & " - " & "Default Adjustments.xlsx")
            End If

            'Clear the employees
            Dest.Resize(3, Columns.Count - Dest.Column).ClearContents
            'Remember this manager
            Login = Data(sourcerow, 2)
            Last = Data(sourcerow, 1)

            'Start the next round
            destcol = 0
        End If

        'Write the employee data into the template
        destrow = 0

        For sourcecol = 1 To UBound(Data, 1)
            Dest.Offset(destcol, destrow) = Data(sourcerow, sourcecol)
            destrow = destrow + 1
        Next

        'Next column
        destcol = destcol + 1
    Next

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...