VBA UDF多单元格引用

我正在尝试创build一个UDF,它从4个选定的单元格中取值,并执行一个函数。 但是我不知道如何编写函数来识别单元格的值。 我现在写的方式我需要input一个值。 任何人都可以帮助我这个相对简单的问题? 这是我迄今为止。

Function solubility(anion As String, cation As String, carbon1 As String, carbon2 As String) 

编辑

因此,例如,我试图select单元格A,C,E和G,它们包含Tf,Mi,Ch和Ch的值。 然后我将使用这些单元格引用一个范围内的对应值来计算并显示一个最终值。 整个代码在下面提供。

 Function solubility(anion As String, cation As String, carbon1 As String, carbon2 As String) Dim sum As Double Dim ncavalue As Long, nanvalue As Long, ncb1value As Long, ncb2value As Long Dim nca As Long, nan As Long, ncab As Long Dim coeff As Range, groups As Range 'solubility groups range groups = Worksheets("Solubility").Range("A2:A33") 'group coefficients range coeff = Worksheets("Solubility").Range("B2:B33") 'number of groups for each group ncavalue = Range("AE" & cation.Row) nanvalue = Range("AC" & anion.Row) ncb1value = Range("AG" & carbon1.Row) ncb2value = Range("AI" & carbon2.Row) j = 0 For j = 0 To UBound(groups) If UCase(anion.Value) = UCase(coeff(j).Value) Then 'coefficient value anvalue = coeff(j).Value End If If UCase(cation.Value) = UCase(coeff(j).Value) Then 'coefficient value cavalue = coeff(j).Value End If If cation.Value = "[MIm]" Then cavalue = Range("B2") ncb1value = ncb1value.Value + 1 End If If UCase(carbon1.Value) = UCase(coeff(j).Value) Then 'coefficient value cb1value = coeff(j).Value End If If UCase(carbon2.Value) = UCase(coeff(j).Value) Then 'coefficient value cb2value = coeff(j).Value End If Next j sum = anvalue * nanvalue + cavalue * ncavalue + cb1value * ncb1value + cb2value * ncb2value solubility = sum + Range("B34").Value End Function 

假设第1行,像这样调用函数:

 =solubility(A1, C1, E1, G1)