我想构建一个宏,它只复制特定单元格(B2)的vlookup函数的返回值,并将其粘贴到列的第一个空单元格(从单元格H2开始的同一工作表上的列H)
答案 0 :(得分:0)
将此宏指定给您的按钮:
Sub CopyVLookup()
Range("H" & Rows.Count).End(xlUp).Offset(1) = [B2]
End Sub
这会在H
列中找到一个带有值的最后一个单元格并移动到其下方的单元格,并将其值设置为等于当前值B2
答案 1 :(得分:0)
如果要捕获的公式在单元格B2中,那么尝试这个小宏:
Sub surface()
Dim n As Long
n = Cells(Rows.Count, "H").End(xlUp).Row + 1
If n < 2 Then n = 2
Range("H" & n).Value = Range("B2").Value
End Sub
答案 2 :(得分:0)
这应该可行,但不测试它:
dim lookingFor as String
dim fromVlookup as String
dim whereToSave as Long
lookingFor = ActiveWorkbook.Worksheets("sheet1).Cells("2", "B").Value
fromVLookup = = Application.WorksheetFunction.VLookup(lookingFor, "A1:B2", 2, 0)
whereToSave = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row
ActiveWorkbook.Worksheets("sheet1).Cells(whereToSave, "H").Value = fromVlookup