Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使范围成为变量?_Excel_Vba - Fatal编程技术网

Excel 如何使范围成为变量?

Excel 如何使范围成为变量?,excel,vba,Excel,Vba,我想根据我最后一行的计算将范围设为一个数字,但我找不到方法 请参阅下面的双星号 Sub TestVBA() OptimizeVBA True Dim startTime As Single, endTime As Single startTime = Timer Dim testnames As Range, testvalues As Range Dim lookupTestNames As Range, lookupTestValues As Ran

我想根据我最后一行的计算将范围设为一个数字,但我找不到方法

请参阅下面的双星号

Sub TestVBA()
    OptimizeVBA True
    Dim startTime As Single, endTime As Single
    startTime = Timer

    Dim testnames As Range, testvalues As Range
    Dim lookupTestNames As Range, lookupTestValues As Range
    Dim vlookupCol As Object

    Dim lastRow As Long
    Dim lCol As Long

    'Dim LastLine As Long
    'LastLine = Range("A" & Rows.Count).End(xlUp).Row

    'Find the last non-blank cell in column A(1)
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row

    'Find the last non-blank cell in row 1
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column


    'Set testnames = Worksheets("Data Analysis").Range("C8:C399")
    **Set testnames = Worksheets("Data Analysis").Range("C8:C&lastRow")**
    Set testvalues = Worksheets("Data Analysis").Range("O8:O399")
    Set lookupTestNames = Worksheets("Graph").Range("A5:A172")
    Set lookupTestValues = Worksheets("Graph").Range("T5:T172")

    'Build Collection
    Set vlookupCol = BuildLookupCollection(testnames, testvalues)

    'Lookup the values
    VLookupValues lookupTestNames, lookupTestValues, vlookupCol
    endTime = Timer
    Debug.Print (endTime - startTime) & " seconds have passed [VBA]"
    OptimizeVBA False
    Set vlookupCol = Nothing
End Sub

在双引号内有
lastRow

不正确

Set testnames=工作表(“数据分析”).Range(“C8:C&lastRow”)

正确

Set testnames=工作表(“数据分析”).Range(“C8:C”和lastRow)