首页 > 解决方案 > Vlookup 不断在 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

标签: excelvba

解决方案


推荐阅读