当我没有在特定的单元格引用中启动时,如何自动填充到最后一行?

时间:2017-02-24 16:11:58

标签: excel vba excel-vba

Search column headers and insert new column using Excel VBA后,我想再问一个问题。

我到了这里:

Dim rngUsernameHeader As Range
Dim rngHeaders As Range

Set rngHeaders = Range("1:1") 'Looks in entire first row.
Set rngUsernameHeader = rngHeaders.Find(what:="Username", After:=Cells(1, 1))

rngUsernameHeader.Offset(0, 1).EntireColumn.Insert
rngUsernameHeader.Offset(0, 1).Value = "Role"
rngUsernameHeader.Offset(1, 1).Value = "=VLOOKUP(K2,Role!A:B,2,0)"
Selection.AutoFill Destination:=Range ???

我对vlookup的问题(因为查找值可能并不总是在列K中)并且还指定了最后一行的范围。我以前用过:

Selection.Autofill Destination:=Range("L2:L" & LastRow)

由于“Role”在我的测试数据的L列中,而查找值在Username列中。这超出了我对VBA的了解!

由于

0 个答案:

没有答案