【发布时间】:2013-12-31 23:13:33
【问题描述】:
我有 2 个工作表。我将有一个宏来在 Sheet1 中进行 Vlookup。 Sheet2 将是存储的数据。但是,每个术语的数据列不会相同,因此我必须检查列名。
这是表格 1。我将输入“会员 ID”然后对表格 2 进行 Vlookup 以获取“会员姓名”和“备注”。
这是第 2 页,所有数据都存储在这里。
这是 Vlookup 代码。
With Sheets("Sheet1")
.Range("G2:G" & .Cells(.Rows.Count, "F").End(xlUp).Row).Formula = "=VLOOKUP(RC[-1],Sheet2!C[-3]:C[-2],2,FALSE)"
End With
With Sheets("Sheet1")
.Range("H2:H" & .Cells(.Rows.Count, "F").End(xlUp).Row).Formula = "=VLOOKUP(RC[-2],Sheet2!C[-4]:C,5,FALSE)"
End With
我试图通过搜索列标题来进行 Vlookup。但我不知道该怎么做。
Worksheets("Sheet2").Activate
' Map Account name
Rows("1:1").Select
Set cell = Selection.Find(What:="Member ID", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
MsgBox "Column 'Member ID' could not be found.", vbCritical, "No such column"
Cancel = True
Else
'Vlookup here
【问题讨论】: