- I wrote a function in VBA:
Function LHV_v(T, compounds As Range, concentrations As Range) As Double
Dim arr() As Variant
Dim i As Long, j As Long, k As Long
Dim curRow As Range
Dim ret As Double, x As Double
ReDim arr(2, 4)
arr(0, 0) = "CH4"
arr(0, 1) = 35.818
arr(0, 2) = 35.808
arr(1, 0) = "C2H6"
arr(1, 1) = 63.76
arr(1, 2) = 63.74
arr(2, 0) = "C3H8"
arr(2, 1) = 91.18
arr(2, 2) = 91.15
If compounds.Rows.Count <> concentrations.Rows.Count Then
MsgBox ("Ranges differ in number of rows")
LHV_v = 0
Exit Function
End If
' Loop through user input rows:
k = 1
For Each curRow In compounds
arraycompound = Trim(UCase(curRow.Value2))
For i = 0 To UBound(arr, 1)
If arr(i, 0) = arraycompound Then
' x retrieves user's input of concentration:
x = concentrations.Cells(k, 1).Value2
If T = 0 Then
ret = ret + arr(i, j + 1) * x
Else
ret = ret + arr(i, j + 2) * x
End If
Exit For
End If
Next
k = k + 1
Next
LHV_v = ret
End Function
which is called as follows::
=LHV_v(25;A19:A23;B19:B23)
- While I'm typing in the formula bar, no hint window pops up (what to type in the function), as is the case with built-in functions, for example:
=SUM([...]
3. How to activate this option for functions created in VBA?