You can add very simple user defined function to your workbook:
Function eval(str As String)
Application.Volatile
eval = Evaluate(Evaluate(Replace(str, ",", ".")))
End Function
and call it in E1
like this: =eval(C1)
Notes:
1) I've used double Evaluate
for the case when data in C1
stores like text without =
sign : 5 & "A1"
. If your data stored with =
sign: =5 & "A1"
, you can use eval = Evaluate(str)
or leave eval = Evaluate(Evaluate(str))
- it doesen't metter
2) since VBA needs .
as delimeter , I've used Replace
function
NEW UPDATE:
But, Evaluate
can operate only with strings less or equal 255 characters..
In that case you can use following UDF:
Public app As Excel.Application
Public wb As Workbook
Function getValue(formulaString As String)
Application.Volatile
Application.DisplayAlerts = False
'set default falue to #REF..if we'd get normal value - we'll change getValue to it'
getValue = CVErr(xlErrRef)
getValue = Evaluate(Evaluate(Replace(formulaString, ",", ".")))
If Not IsError(getValue) Then
Exit Function
End If
'if we appear here - second WB is closed...'
On Error GoTo ErrHandler
If app Is Nothing Then Set app = New Excel.Application
If wb Is Nothing Then Set wb = app.Workbooks.Open(ThisWorkbook.FullName)
With wb.Sheets(ThisWorkbook.ActiveSheet.Name)
With .Range(Application.ThisCell.Address)
.FormulaLocal = IIf(Left(formulaString, 1) <> "=", "=" & formulaString, formulaString)
.Calculate
getValue = .Value
End With
End With
ErrHandler:
Application.DisplayAlerts = True
End Function
and last thing: add following code to the ThisWorkbook
module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not wb Is Nothing Then wb.Close False
If Not app Is Nothing Then app.Quit
Set app = Nothing
Set wb = Nothing
End Sub