0

我正在尝试创建一个跟踪间接公式先例的宏。看起来像这样的间接公式: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
4

1 回答 1

0
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
于 2015-08-24T16:40:29.947 回答