VBA:获取最后一行的数据/值/内容

时间:2017-05-18 09:41:20

标签: excel-vba vba excel

是否可以通过此方法获取所选最后一行的值/数据/内容?我怎么得到它。谢谢。

Dim WhatChapter As String
WhatChapter = InfoForm.Chapter

If WhatChapter <> "" Then
    With ActiveSheet
        lastRow = Cells(.Rows.Count, "A").End(xlUp).Row
    End With
End If

2 个答案:

答案 0 :(得分:0)

您的问题有很多可行的方法。 我通常做的是,找到工作表中的最低范围并结束xlUp之类的,

Dim rLastNonBlankCell as Range
Dim LastRow as Long
Set rLastNonBlankCell = Sheet[x].Range("A1048576").End(xlUp)
LastRow = rLastNonBlankCell.Row

答案 1 :(得分:0)

我找到了解决此问题的简便方法。

如果要从lastRow获取VALUE,可以使用以下方法:

Dim rows As String
Dim value As String
Dim concat As String

rows = Range("A1048576").End(xlUp).Row

Dim a As String
'Column
a = "A"
concat = a & rows
'Value in last low is below
value = Range(concat).value

MsgBox (value)

我希望此解决方案对其他人有帮助