Add unknown variables to Excel

Annie Caron picture Annie Caron · Apr 18, 2016 · Viewed 8.7k times · Source

Here is a screenshot from my TI CAS: TI-CAS

I would like to do the same into an Excel file. I want to put "x" in a cell and make other cells compute with it.

Is there a way to add "unknown variables" to Excel? I don't want it to solve anything, but I need to have values like: 0.06*x+66000

EDIT

For example, if D2 = x and E3 = 2, I want to have "x-2" if I enter "=D2-E3" in a cell.

EDIT

The "x" must be evaluate, not only concatenate. It must simplify the next equation like shown in the screenshot. For example, if you have: A1: x-2 and A2: 3, if you do: A3: =A1*A2 you should have: 3x-6.

Answer

OldUgly picture OldUgly · Apr 18, 2016

Here it is with a user defined function.

enter image description here

And the code ...

Public Function MakeEqn(inputStr As String) As String
Dim tempStr As String
Dim rngStr As String

Dim myRng As Range
Dim iLoop As Long, jLoop As Long

    Application.Volatile

    tempStr = ""
    Set myRng = Nothing
    iLoop = 1
    Do While iLoop + 1 <= Len(inputStr)
        On Error Resume Next
        For jLoop = 2 To 4
            rngStr = Mid(inputStr, iLoop, jLoop)
            Set myRng = Range(rngStr)
            If Not myRng Is Nothing Then Exit For
        Next jLoop
        On Error GoTo 0
        If myRng Is Nothing Then
            tempStr = tempStr & Mid(inputStr, iLoop, 1)
        Else
            tempStr = tempStr & myRng.Value
            Set myRng = Nothing
            iLoop = iLoop + jLoop - 1
        End If
        iLoop = iLoop + 1
    Loop

    MakeEqn = tempStr
    Set myRng = Nothing
End Function