View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kirk L. Kirk L. is offline
external usenet poster
 
Posts: 1
Default Creating a new function

I'm trying to create a function to help determine rates.

There are four cells to be examined, and based on the selection of the
four cells, it will spit out a value in another cell.
The first cell, choice is Single or Family
second, third and fourth cell, all have a choice of A, B or C.

The problem is what I plunk this function into a cell in the
spreadsheet, I get a "#VALUE" error. I'm VERY new to VB, and I'm
hoping someone out there could help me out. Any help would be greatly
appreciated.

Here's what I have:

Function Benefits(Selection, Health, Dental, Drug As String)
Dim TotalHealth, TotalDental, TotalDrug As Integer
Dim SHealthA, SHealthB, SHealthC As Integer
Dim SDentalA, SDentalB, SDentalC As Integer
Dim SDrugA, SDrugB, SDrugC As Integer
Dim FSHealthA, FHealthB, FHealthC As Integer
Dim FSDentalA, FDentalB, FDentalC As Integer
Dim FSDrugA, FDrugB, FDrugC As Integer
Dim Benefit As Integer

'Rate Table (Single)
SHealthA = "insert rates here"
SHealthB = "insert rates here"
SHealthC = "insert rates here"
'etc., as dim'd above.

'Rate Table (Family)
FHealthA = "insert rates here"
FHealthB = "insert rates here"
FHealthC = "insert rates here"
'etc., as dim'd above.

'Single
If Selection = "Single" Then
'Health Selection
If Health = "A" Then
TotalHealth = SHealthA
ElseIf Health = "B" Then
TotalHealth = SHealthB
Else
TotalHealth = SHealthC
End If
'Dental Selection
If Dental = "A" Then
TotalDental = SDentalA
ElseIf Dental = "B" Then
TotalDental = SDentalB
Else
TotalDental = SDentalC
End If
'Drug Selection
If Drug = "A" Then
TotalDrug = SDrugA
ElseIf Drug = "B" Then
TotalDrug = SDrugB
Else
TotalDrug = SDrugC
End If

'Family
Else
'Health Selection
If Health = "A" Then
TotalHealth = FHealthA
ElseIf Health = "B" Then
TotalHealth = FHealthB
Else
TotalHealth = FHealthC
End If
'Dental Selection
If Dental = "A" Then
TotalDental = FDentalA
ElseIf Dental = "B" Then
TotalDental = FDentalB
Else
TotalDental = FDentalC
End If
'Drug Selection
If Drug = "A" Then
TotalDrug = FDrugA
ElseIf Drug = "B" Then
TotalDrug = FDrugB
Else
TotalDrug = FDrugC
End If

End If
'Calculation
Benefit = TotalHealth + TotalDrug + TotalDental
ActiveCell.Value = Benefit
End Function