在excel VBA VLookup中使用变量作为图纸名称

在excel VBA VLookup中使用变量作为图纸名称,vba,excel,vlookup,Vba,Excel,Vlookup,变量“sheet”最终将根据嵌套的if进行更改。然后应将其传递到End Sub之前的最后一行代码。我收到一个编译错误,该错误声明为“Expected:expression”,它突出显示了'“&sheet&'”中的第一个勾号,类似于: Private Sub UpdateBoxes() Dim wsFunc As WorksheetFunction: Set wsFunc = Application.WorksheetFunction Dim sheet As String

变量“sheet”最终将根据嵌套的if进行更改。然后应将其传递到
End Sub
之前的最后一行代码。我收到一个编译错误,该错误声明为“Expected:expression”,它突出显示了
'“&sheet&'”

中的第一个勾号,类似于:

Private Sub UpdateBoxes()
    Dim wsFunc As WorksheetFunction: Set wsFunc = Application.WorksheetFunction
    Dim sheet As String
    If Range("C1") = "some string" Then
        sheet = "SomeSheet"
    End If

    Range("B6").Value = Sheets("Spreadsheet Ctrl").Range("B7") 'Sets title of Box 1 based on Spreadsheet Ctrl
    Range("G6").Value = Sheets("Spreadsheet Ctrl").Range("C7") 'Sets title of Box 2 based on Spreadsheet Ctrl
    Range("B11").Value = Sheets("Spreadsheet Ctrl").Range("D7") 'Sets title of Box 3 based on Spreadsheet Ctrl
    Range("G11").Value = Sheets("Spreadsheet Ctrl").Range("E7") 'Sets title of Box 4 based on Spreadsheet Ctrl
    Range("B16").Value = Sheets("Spreadsheet Ctrl").Range("F7") 'Sets title of Box 5 based on Spreadsheet Ctrl
    Range("G16").Value = Sheets("Spreadsheet Ctrl").Range("G7") 'Sets title of Box 6 based on Spreadsheet Ctrl

    Range("C7").Value = wsFunc.VLookup(B6,'" & sheet & '"!A1:G5,3,)" 'Vlookup for "Current Revision
End Sub

Range(“C7”).Value=wsFunc.VLookup(ActiveSheet.Range(“B6”)、Sheets(sheet.Range)(“A1:G5”)、3、)“当前修订版”的VLookup
这会导致一个编译错误:“Expect:Expression”突出显示最后一个右括号。你太棒了。成功了。谢谢我没有意识到这是明确要求的,因为它不在标准公式中。
Range("C7").Value = wsFunc.VLookup(ActiveSheet.Range("B6"), _
                                   Sheets(sheet).Range("A1:G5"),3,False)