我是一名全科医生,正在尝试建立一个 Excel 表来根据血糖水平调整胰岛素剂量。
为此,我需要制作一个这样的公式 IF(F8<=B15;D9+C15),OR,IF(F8<=B16;D9+C16),OR,IF(F8<=B17;D9+C17),OR,IF(F8<=B18;D9+C18),OR,IF(F8<=B19;D9+C19)
所以这意味着我的血糖水平为“F8”,如果低于 B15,那么胰岛素剂量应该是 D9 加上“调整”
先感谢您!
答案1
我猜这就是你要找的东西
=如果(F8<=B15,D9+C15,如果(F8<=B16,D9+C16,如果(F8<B17,D9+C17,如果(F8<B18,D9+C18,如果(F8<=B19,D9+C19,0)))))
如果 F8 > B19,则假设值为 0。基本上这是
IF F8<=B15
result = D9+C15
ELSEIF F8<=B16
result = D9+C16,
ELSEIF F8<B17
result = D9+C17,
ELSEIF F8<B18
result = D9+C18,
ELSEIF F8<=B19
result = D9+C19
ELSE
result = 0
希望这就是你正在寻找的
** 编辑 VBA 版本 **
如果您使用 VBA,公式不必限制在一行
Const levels = 4
Dim glycemia(levels) As Double
Dim insulin_adj(levels) As Double
Dim insulin_base As Double
Sub InsulinDoseInit()
' Initialize the data
Dim sht As Worksheet
Set sht = Worksheets("Sheet1")
insulin_base = sht.Cells(9, 4) ' D9
For lvl = 0 To levels
glycemia(lvl) = sht.Cells(15 + lvl, 2) 'b15 etc
insulin_adj(lvl) = sht.Cells(15 + lvl, 3) 'c15 etc
Next
End Sub
Function InsulinDose(glycemia_lvl As Double) As Double
Dim dose As Double
dose = 0
For lvl = 0 To levels
' instead of using nested if, just loop through until
' the level is found, then set the dose and exit
If glycemia_lvl <= glycemia(lvl) Then
dose = insulin_base_level + insulin_adj(lvl)
Exit For
End If
Next
InsulinDose = dose
End Function
Sub TestFunction()
InsulinDoseInit
' To see the result, Ctrl+G, look at the immediate window
Debug.Print InsulinDose(7.8)
Debug.Print InsulinDose(5#) ' 5.0 as a double otherwise it is an integer
Debug.Print InsulinDose(10.3)
Debug.Print InsulinDose(12.9)
End Sub