First question, and I apologize if it has been asked before (I have searched the forums but did not find any posts that I recognized as a possible solution). If you're aware of another post that address this issue, please share the link!
Context: I teach a college course, and my exams are partially completed worksheets that the students have to write the formulas to complete (similar to the ModelOff applied problems if you're familiar with those). I have a "scorecard" in the file that compares the output of their formulas to the correct output and gives them points if they match.
My problem is, that for formulas that are dependent on prior inputs being calculated correctly, the scorecard marks the cell as wrong if the formulas is correct but the precedent values are wrong. I don't want this, because I am evaluating the formula, not the result (if that makes sense). It occurred to me, that I might be able to create a custom function that takes the formula as an input and modifies the cell references to ones containing the correct precedents, and then evaluating the formula for the value it returns. I have been able to make it work with formulas that have ranges. Here is a limited example:
What I need, is a method of extracting individual cell references when it's not a range involved (e.g., SUM(A1,B1,C1) instead of SUM(A1:C1)). Ideally, the extracted cell references would be stored in a string array (I sort of envision this as a tokenizer).
The one caveat, I do not know what the operators in the formula will be in advance, so I cannot use them as delimiters.
Context: I teach a college course, and my exams are partially completed worksheets that the students have to write the formulas to complete (similar to the ModelOff applied problems if you're familiar with those). I have a "scorecard" in the file that compares the output of their formulas to the correct output and gives them points if they match.
My problem is, that for formulas that are dependent on prior inputs being calculated correctly, the scorecard marks the cell as wrong if the formulas is correct but the precedent values are wrong. I don't want this, because I am evaluating the formula, not the result (if that makes sense). It occurred to me, that I might be able to create a custom function that takes the formula as an input and modifies the cell references to ones containing the correct precedents, and then evaluating the formula for the value it returns. I have been able to make it work with formulas that have ranges. Here is a limited example:
Code:
Public Function FormulaTest(Cell As Range) As Boolean
Dim CellFormula As Variant
Dim D15Test As Double
Dim Rng As Range
D15Test = Worksheets("Comparison Worksheet").Range("D15").Value
Debug.Print (Cell.Formula)
If InStr(Cell.Formula, ":") <> 0 Then
CellFormula = Replace(Cell.Formula, Cell.Address, "'Comparison Worksheet'!" & Cell.Address)
Debug.Print (CellFormula)
If Evaluate(CellFormula) = D15Test Then
FormulaTest = True
Else
FormulaTest = False
End If
Else
End If
End Function
What I need, is a method of extracting individual cell references when it's not a range involved (e.g., SUM(A1,B1,C1) instead of SUM(A1:C1)). Ideally, the extracted cell references would be stored in a string array (I sort of envision this as a tokenizer).
The one caveat, I do not know what the operators in the formula will be in advance, so I cannot use them as delimiters.