更改工作表(“数据”)。选择包含您的数据的工作表的实际名称
Sub VLookupMacro()
Dim FormulaCol As Long
Dim LookupCol As Long
Dim TotalRows As Long
Dim TotalCols As Long
Dim i As Long
Sheets("Data").Select
TotalRows = ActiveSheet.UsedRange.Rows.Count
TotalCols = ActiveSheet.UsedRange.Columns.Count
For i = 1 To TotalCols
If Cells(1, i).Value = "Hot Data Campaign ID" Then FormulaCol = i
If Cells(1, i).Value = "Source Code" Then LookupCol = i
Next
Cells(2, FormulaCol).Formula = "=VLOOKUP(" & Cells(2, LookupCol).Address(False, False) & ",Vlookup!A:D,2,FALSE)"
Cells(2, FormulaCol).AutoFill Destination:=Range(Cells(2, FormulaCol), Cells(TotalRows, FormulaCol))
With Range(Cells(2, FormulaCol), Cells(TotalRows, FormulaCol))
.Value = .Value
End With
End Sub