VBA 在 Table 列中查找具有值的最后一行

VBA Finding Last Row with Value in Table Column

我有一个 table,里面有几个项目。这些项目都有一个代码,它们会逐行重复。我的意思是挑出 table 中某个项目的最后一个 'repetition',我需要有地址或行引用,我可以使用这些东西以便稍后将它带到一个新的 [=21] =],我将每月概述我们项目的当前状态,出现在第一个 table 中。 而且我已经快搞定了,下面的代码:

'codTeste is a integer in this example
codTeste = Range("AE:AE").Find(what:="REST0300", after:=Range("AE1"), searchdirection:=xlPrevious).Row

确实有效,但没有这样的方法:

codTeste = Range(tblDesc.DataBodyRange.Address).Find(what:="REST0300", after:=Range(TheFirstCellOfTheRelevantColumnDataBodyRange), searchdirection:=xlPrevious).Row
    'If I do this it'll throw me a mismatch error

重点是使其更具动态性,以免将查找方法限制在非常具体的范围参数...

这对我有用:

Dim trng As Range, f As Range, inCol As Long
Set trng = ActiveSheet.ListObjects("Table1").DataBodyRange

useCol = 2

Set f = trng.Columns(inCol).Find(what:="77", LookIn:=xlValues, lookat:=xlWhole, _
        searchdirection:=xlPrevious, after:=trng.Columns(inCol).Cells(1))

If Not f Is Nothing Then Debug.Print f.Row

将 inCol 变暗为整数

inCol = Worksheets("Sheet1").Cells.Find(内容:="Product Code", 之后:=Worksheets("Sheet1").Range("A1" ), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column

我无法发表评论,但这会找到给定名称@steps

的列号