Hi All!
I'm trying to create a function in VBA so that when you choose from the drop down box in cell D6 it executes a formula in D7. If you don't mind taking a look at the VBA code I wrote, I know there is something wrong with it (never used VBA)!
Function CalcValue(Target_Product As String)
If Target_Product = "Conventional Hypo" Then
CalcValue = B6 * 5
ElseIf Target_Product = "Safety Hypo" Then
CalcValue = B6 * 18
ElseIf Target_Product = "Syringes" Then
CalcValue = B6 * 38
ElseIf Target_Product = "Autoneedle" Then
CalcValue = B6 * 8
ElseIf Target_Product = "Sharps" Then
CalcValue = (B6 * 16) + (75 * B6)
ElseIf Target_Product = "N" Then
CalcValue = B6 * 95
ElseIf Target_Product = "AutoG" Then
CalcValue = B6 * 46
ElseIf Target_Product = "AutoG BC" Then
CalcValue = B6 * 53
ElseIf Target_Product = "Ste" Then
CalcValue = B6 * 45
ElseIf Target_Product = "Trays" Then
CalcValue = (B6 * 12) + (B6 * 9)
Else
CalcValue = 0
End If
End Function
Also, I found that if I put in a nested "If-Else" function in the cell itself it works, yet Excel'03 only allows me to have 7 variables. I've gotten the nested formula to work for "Conventional Hypo" and "Sharps".
IF(D6="Sharps",(B6*O23+(O20*B6)),IF(D6="Conventional Hypo",(B6*O8)))
Thanks for taking a look at this... I wish I knew VBA better!
Pnasri
I'm trying to create a function in VBA so that when you choose from the drop down box in cell D6 it executes a formula in D7. If you don't mind taking a look at the VBA code I wrote, I know there is something wrong with it (never used VBA)!
Function CalcValue(Target_Product As String)
If Target_Product = "Conventional Hypo" Then
CalcValue = B6 * 5
ElseIf Target_Product = "Safety Hypo" Then
CalcValue = B6 * 18
ElseIf Target_Product = "Syringes" Then
CalcValue = B6 * 38
ElseIf Target_Product = "Autoneedle" Then
CalcValue = B6 * 8
ElseIf Target_Product = "Sharps" Then
CalcValue = (B6 * 16) + (75 * B6)
ElseIf Target_Product = "N" Then
CalcValue = B6 * 95
ElseIf Target_Product = "AutoG" Then
CalcValue = B6 * 46
ElseIf Target_Product = "AutoG BC" Then
CalcValue = B6 * 53
ElseIf Target_Product = "Ste" Then
CalcValue = B6 * 45
ElseIf Target_Product = "Trays" Then
CalcValue = (B6 * 12) + (B6 * 9)
Else
CalcValue = 0
End If
End Function
Also, I found that if I put in a nested "If-Else" function in the cell itself it works, yet Excel'03 only allows me to have 7 variables. I've gotten the nested formula to work for "Conventional Hypo" and "Sharps".
IF(D6="Sharps",(B6*O23+(O20*B6)),IF(D6="Conventional Hypo",(B6*O8)))
Thanks for taking a look at this... I wish I knew VBA better!
Pnasri
Last edited: