3

Excel でセルをクリックすると、 のような数式が表示されます=A1+B1。それがセル参照を含む式です。たとえば、セルの値を含む数式を表示したい: =10+20.

A1 =10           //Cell A1 has the value 10
A2 =20           //Cell A2 has the value 20
C2 =A1+B1        //Cell C2 has the value A1 + A2

D2 =10+20        //I want Excel to derive this.

数式をセルなどに表示したくありません。私はまだ C2 に 30 を表示させたいと思っています。C2 をクリックすると=10+20数式バーに表示されるようにしたいだけです。

あるいは、C2 が計算を示すコメントを表示した場合 (したがって、C2 をクリックするとコメント「=10+20」が表示されます)、それも機能します。

4

5 に答える 5

4

それは Excel のしくみではありません。セルに数式がある場合、それが数式バーに表示されます。

編集

ただし、 VBA (from Tools > Macros > Visual Basic Editor) を使用して、C セルの内容を A + B の値で更新するコードを次のように記述できます。

Private Sub HideFormula()
    Dim lastrow As Long, r1 As Long

    ' Get the last row in the worksheet
    lastrow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row

    For r1 = 1 To lastrow

        ' If A & B aren't blank, make the formula of cell C equal to A + B.
        If Sheet1.Range("$A$" & r1).Value <> "" And _
            Sheet1.Range("$B$" & r1).Value <> "" Then

            ' In the example, C2 = A1 + B1, so offset C by one
            Sheet1.Range("$C$" & (r1 + 1)).Value = _
                "=" & Sheet1.Range("$A$" & r1).Value & "+" & _
                Sheet1.Range("$B$" & r1).Value

        End If

    Next

End Sub

編集2

C セルの内容を数式の値に置き換えたい場合は、.Formula値を使用してその数式を見つけ、そこから移動できます。

Private Sub ReplaceFormulaWithValues()
    Dim lastrow As Long, r1 As Long
    Dim temp As String, arTemp

    ' Get the last row in the worksheet
    lastrow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row

    For r1 = 1 To lastrow

        ' If A & B aren't blank, make the formula of cell C equal to A + B.
        If Sheet1.Range("$C$" & r1).Value <> "" Then

            ' Get the formula for the current C cell
            temp = Replace(Sheet1.Range("$C$" & r1).Formula, "=", "")

            ' Create an array by splitting the formula on the + sign
            arTemp = Split(temp, "+")

            Sheet1.Range("$C$" & r1).Value = _
                "=" & Sheet1.Range(arTemp(0)).Value & "+" & _
                Sheet1.Range(arTemp(1)).Value


        End If

    Next

End Sub
于 2012-07-20T12:59:49.310 に答える
3

不可能ですが、値をすばやく特定したいという理由がある場合は、ユーザーがすべてのセルと範囲を特定する必要なく、1 シート内の関連フィールドに矢印を描画する「Trace Precedents」を使用できます。時間。
これがあなたの目的である場合、おそらく役立つでしょう...
この機能は、リボンの [数式] タブにあります。

于 2012-07-20T13:03:21.163 に答える