Reputation: 31
trying to create my first UDF, I keep getting Compile error: Sub or Function not defined. completely self taught, trying this out as a hobby. I get the first line highlighted on this error, here's my code.
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
I know this is just a bunch of nested if()'s, but I wanted to start with something simple, and I would be doing this within vlookup()'s. Here's the chart I'm basing this off of. What my function is quantifying basically, just figuring out skill level cost when presented with defining attribute lvl, desired skill lvl, and difficulty of skill.
Upvotes: 0
Views: 148
Reputation: 152505
As per my comment look into 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
This is just here for reference. @Gary'sStudent pointed out the error.
Upvotes: 1
Reputation: 96753
Spelling error here:
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
Upvotes: 2