我在 vlookup 公式中遇到了变量工作表的问题。我相信这与我引用工作表的方式有关。我查看了许多其他关于此的博客并使用了不同的技术,但我仍然收到“运行时错误 1004”。以下是相关代码的摘要 - 任何帮助将不胜感激。
Sub PopulateDynamicReport()
Dim getcolumnPDR As Range
Dim getConfigPosition As Range
Dim getFieldDescriptionPDR As String
Dim getFormulaPDR As Variant
Dim columnletter As String
Dim myrange As String
Dim getColumnLetter As String
Dim counter As Long
Dim lLastrow As Long
Dim ws As Worksheet
lLastrow = FindLastRow("Pricing Analysis")
Sheets("Pricing Analysis").Cells.Clear
counter = 1
Set getConfigPosition = Sheets("Config").Cells.Find(What:="Field Description", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Offset(counter, 0)
columnletter = getConfigPosition.Offset(0, -1)
Set ws = Sheets(getConfigPosition.Offset(0, 2).Value)
Sheets("Pricing Analysis").Cells(1, columnletter).FormulaR1C1 = "=VLOOKUP(RC[-4],ws.range(!C[-4]:C[-2]),3,FALSE)"
counter = counter + 1
End Sub