how to reference the cell the function is called from
<h1>Situation</h1>
<p>I want to create a user defined function that will solve a string equation in a designated cell after replacing the variable in the string with values.</p>
<p>The information is always in two columns.  The top of the first column will contain a formula stored as a string.  The bottom of the first column will contain the UDF.  Between the formula and the UDF will be all the variables from the string formula.  The second column will contain all the numeric values for the variables.</p>
<h1>Problem</h1>
<p>I do not know how to select to top of the column of information or the variables above the UDF in an automatic method since I do not know how to define the location of the cell the UDF is placed in.</p>
<h1>Objective</h1>
<p>Reference the location of the cell the UDF is in so that the location of the formula cell and the range for the variable cells can be defined.  I am trying to write the UDF in a fashion that I do not have to pass it the address of the formula cell or the variables.  I want it to grab that information on its own based on all the information being immediately adjacent to the cell with the UDF with no gaps.</p>
<h1>What I Have</h1>
<pre><code> Option Explicit

 Public Function SolvedEquation() As Long

 Dim FormulaCell As Range
 Dim Equation As String
 Dim VariableRange As Range
 Dim VariableCell As Range
 Dim VariablesLength As Integer
 Dim Variable As String
 Dim VariableValue As Double

 'define FormulaCell as the last nonblank up from the cell the function is called in from a contiguous range(no spaces)
 FormulaCell = Application.ThisCell.End(xlUp).Select

 'define the VariableRange as one up from the cell the function is called to second last cell non blank cell located upward in a contiguous selection (no spaces)
 VariableRange = Range(Cells(Application.ThisCell.Row - 1, Application.ThisCell.Column), Cells(FormulaCell.Row + 1, FormulaCell.Column))

 Equation = FormulaCell.Value

 For Each VariableCell In VariableRange.Cells

     VariablesLength = Len(VariableCell.Value)-1
     Variable = Left(VariableCell.Value, VariablesLength)
     VariableValue = Cells(VariableCell.Row, VariableCell.Column + 1).Value
     Equation = Replace(FormulaCell.Value, Variable, VariableValue)

 Next VariableCell

 SolvedEquation = Evaluate(Equation)

 End Function
</code></pre>
<p>Suggestions for better coding appreciated (ie choice of range over cells)</p>
<h1>Example of data</h1>
<p><a href="https://i.stack.imgur.com/GE7hy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GE7hy.jpg" alt="enter image description here" /></a></p>
<p>With some code corrections from the individuals below I wound up with this so far.  Where the 177.00 in the cell shows up, it should be reading 176.86.  CORRECTION: got this last problem fixed by redefining the variable type as Chris did in his feedback.</p>