创建宏以跟踪间接函数的先例

To create a macro to trace precedents of an indirect function

我正在尝试创建一个宏来跟踪间接公式的先例。间接公式如下所示:indirect(Sheetname, column, row, TRUE)。我尝试了以下代码。但是它不起作用,我不知道为什么。因此,如果有人可以帮助我,那就太好了。提前致谢!

Sub GetCell()
Dim c As Range

On Error Resume Next
Set c = Selection.Parent.Evaluate(Selection.Formula)
On Error GoTo 0
If Not c Is Nothing Then
    If c.Parent.Name <> ActiveSheet.Name Then c.Parent.Activate
    c.Select
End If

End Sub
Dim strFormula As String, strBetweenParenthesis As String, strNewFormula as String
Dim lPos As Long, lNextChar As Long, lStart As Long, lEnd As Long
dim rSource as range

Set rSource = ActiveCell
strFormula = rSource.Formula
strNewFormula = strFormula
lPos = InStr(1, strFormula, "INDIRECT")

If lPos > 0 Then

    Do
        lStart = lPos + Len("INDIRECT")
        lEnd = InStr(lStart, strNewFormula, ")")
        strBetweenParenthesis = Mid(strNewFormula, lStart, lEnd - lStart + 1)
        strNewFormula= Replace(strNewFormula, "INDIRECT" & strBetweenParenthesis, Evaluate(strBetweenParenthesis))
        lPos = InStr(lEnd - Len("INDIRECT" & strBetweenParenthesis) + Len(Evaluate(strBetweenParenthesis)), strNewFormula, "INDIRECT")
    Loop Until lPos = 0

    rSource.Formula = strNewFormula
End If

rSource.ShowPrecedents
rSource.NavigateArrow True, 1
rSource.ShowPrecedents(True)
rSource.Formula = strFormula