Vlookup在VBA脚本中不断生成错误

时间:2019-05-20 17:34:41

标签: excel vba

我的Vlookup不断使我的代码失败。一些见识会很棒。否则我的代码可以正常工作。

Sub PopulateSSPplate()

    On Error Resume Next
    Application.ScreenUpdating = False
    SampleCount = ThisWorkbook.Sheets("LIMS_Import").Range("D1000").End(xlUp).Row - 3
    Dim Sheet1 As Worksheet
    Dim Sheet2 As Worksheet
    Dim Range1 As Range

    Set Range1 = ThisWorkbook.Sheets("Samples").Range("AK2:AL145")
    Set Sheet1 = ThisWorkbook.Sheets("Samples")
    Set Sheet2 = ThisWorkbook.Sheets("SSP Plate")

    For Y = 0 To 1
     'MsgBox (Y)
        For X = 0 To 2
        'MsgBox (X)
            For j = 1 To 6
                'MsgBox (j)
                For k = 1 To 4
                    Sheet2.Cells((3 + k), (2 + j)).Offset((6 * X), (8 * Y)).Value = Application.WorksheetFunction.VLookup(Sheet2.Range("T3"), Range1, 2, False)
                   ' MsgBox (ThisWorkbook.Sheets("SSP Plate").Cells((3 + k), (2 + j)).Offset((6 * X), (9 * Y)).Value)
                    SampleCount = SampleCount - 1
                    'MsgBox (SampleCount)
                    If SampleCount = 0 Then
                        Exit For
                    End If
                Next k
                'MsgBox (SampleCount)
                If SampleCount = 0 Then
                    Exit For
                End If
            Next j
            'MsgBox (SampleCount)
            If SampleCount = 0 Then
                    Exit For
            End If
        Next X
        'MsgBox (SampleCount)
         If SampleCount = 0 Then
            Exit For
         End If
    Next Y

Application.ScreenUpdating = True
 End Sub

0 个答案:

没有答案