尝试创建我的第一个UDF,我不断收到编译错误:Sub或Function未定义。完全自学成才,尝试将其作为一种爱好。我得到第一行突出显示此错误,这是我的代码。
Function SkillCost(AttrLVL, SkillLVL, E_A_H)
If E_A_H = "E" Then
If SkillLVL - AttrLVL < 0 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < 1 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 2 Then
SkillCost = 2
Else
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
End If
End If
End If
Else
If E_A_H = "A" Then
If SkillLVL - AttrLVL < -1 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < 0 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 1 Then
SkillCost = 2
Else
SkillCost = (SkillLVL - AttrLVL) * 4
End If
End If
End If
Else
If E_A_H = "H" Then
If SkillLVL - AttrLVL < -2 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < -1 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 0 Then
SkillCost = 2
Else
SkillCost = ((SkillLVL - AttrLVL) + 1) * 4
End If
End If
End If
End If
End If
End If
End Function
我知道这只是一堆嵌套的if(),但我想从简单的东西开始,我会在vlookup()中做这个。这是我基于此的图表。 What my function is quantifying基本上,只是在提出定义属性lvl,所需技能lvl和技能难度时计算技能等级成本。
答案 0 :(得分:2)
拼写错误:
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
答案 1 :(得分:1)
根据我的评论,请查看Select Case
:
Function SkillCost(AttrLVL, SkillLVL, E_A_H)
If E_A_H = "E" Then
Select Case SkillLVL - AttrLVL
Case Is < 0
SkillCost = 0
Case Is < 1
SkillCost = 1
Case Is < 2
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "A" Then
Select Case SkillLVL - AttrLVL
Case Is < -1
SkillCost = 0
Case Is < 0
SkillCost = 1
Case Is < 1
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "H" Then
Select Case SkillLVL - AttrLVL
Case Is < -2
SkillCost = 0
Case Is < -1
SkillCost = 1
Case Is < 0
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
End If
End Function
这只是供参考。 @ Gary&#s; sStudent指出了这个错误。