我有 Excel 工作表,其中包含来自许多来源的数据,这些数据将组合在一起,以便需要查看的内容高于您正在查看的内容,因此一张工作表的不同部分会有许多 VLookup。
Sub linkFDCfdv()
Range("A1").Select
Dim doesFDChaveDescription As Boolean
Dim isLastRowFDC As Boolean
Dim myRange As String
Dim firstFDCrow As Long
Dim lastFDCrow As Long
While Len(Selection.Value) > 0
If Selection.Value = "FDC" Then
If isLastRowFDC = False Then
firstFDCrow = ActiveCell.Row
End If
isLastRowFDC = True
ActiveCell.Offset(0, 3).range("A1").Select
If Len(Selection.Value) > 0 Then
doesFDChaveDescription = True
Else
doesFDChaveDescription = False
End If
ActiveCell.Offset(0, -3).range("A1").Select
Else
If isLastRowFDC = True Then
lastFDCrow = ActiveCell.Row - 1
End If
End If
If Selection.Value = "FDV" Then
ActiveCell.Offset(0, 10).range("A1").Select
myRange = "B" & firstFDCrow & ":D" & lastFDCrow
ActiveCell.Formula = "=VLOOKUP(R[0]C[-2]," & myRange & ",2)"
ActiveCell.Offset(0, -10).range("A1").Select
End If
ActiveCell.Offset(1, 0).range("A1").Select
Wend
End Sub
发生的事情是我的宏使公式:
=VLOOKUP(I9,'B3':'D8',2)
如果我去掉'
标记,宏就可以完美运行。