0
Sub WS()
    Application.ScreenUpdating = False
    For Each Mar In ActiveWorkbook.Worksheets
        Mar.Select
        ActiveCell.Value = Selection.SpecialCells(xlCellTypeLastCell).Address(False, False)
        ActiveCell.Offset(1, 0).Select
        Next Mar
    Application.ScreenUpdating = True
End Sub

那么我怎么称呼它的价值呢?我有 10 张不同的表格,我想提取 10 张不同表格的最后一个单元格的地址。

4

1 回答 1

1

尝试这样的事情。您的问题有点不清楚,因为您既提到了最后一个单元格Address我想提取最后一个单元格的地址),又提到了一些关于Value我如何调用这些值)的内容。上面的代码将检索Address最后一个单元格的值,但还包括检索值的代码,您只需注释掉一行并取消注释另一行。

Sub LastCellAddresses()
    Dim Mar As Worksheet
    Dim myValues As Variant
    Dim i As Integer: i = 1

    '## Create an Array with one item for each worksheet
    ReDim myValues(1 To ActiveWorkbook.Worksheets.Count)

    '## iterate the worksheets and add values to the array
    For Each Mar In ActiveWorkbook.Worksheets

        '## Use one of these, depending on what you're trying to do.
        ' This line returns the ADDRESS
        myValues(i) = Mar.Cells.SpecialCells(xlCellTypeLastCell).Address
        ' OR this line returns the VALUES
        'myValues(i) = Mar.Cells.SpecialCells(xlCellTypeLastCell).Value
        i = i + 1
    Next Mar

    '## Print each value from the array in its own row, from
    '   the activeCell
    '   Modify as needed
    ActiveCell.Resize(UBound(myValues)).Value = Application.Transpose(myValues)

End Sub
于 2013-11-14T15:06:54.243 回答