sortosane
05-18-2011, 12:28 PM
I'm new to VBA and work for a very small company that is needing some Excel magic through VBA. They need a custom If function that can go as far as 50 (so far) logical_test values. Thank fully they are literally 1 thru 50, but the resulting data is all over the place as product dimensions. I've tried searching the web and these forums for some kind of help with understanding what I'm doing wrong, but I can't even seem to replicate some of the if...then...else examples I'm finding:banghead:. To be honest I'm not sure that if...then...else is really what will be needed, but I would think so since the old nested if function fell apart when it got too large. Here is what I have...
Function Shipping(val)
If val = 1 Then 6.84
ElseIf val = 2 Then 7.84
ElseIf val = 3 Then 8.67
ElseIf val = 4 Then 928
ElseIf val = 5 Then 9.80
ElseIf val = 6 Then 10.00
ElseIf val = 7 Then 10.34
ElseIf val = 8 Then 10.96
ElseIf val = 9 Then 11.64
ElseIf val = 10 Then 12.41
End If
End Function
For the sake of simplicity I'm only listing through 10. I get all kinds of differnet errors while just trying to make this. Actually I'd love to be able to have either a separate sheet or workbook that could contain the data that a custom function could refer to for ease of maintaining but I haven't the foggiest if that is even possibly.
Thank you for any help and direction.
Sortosane
Function Shipping(val)
If val = 1 Then 6.84
ElseIf val = 2 Then 7.84
ElseIf val = 3 Then 8.67
ElseIf val = 4 Then 928
ElseIf val = 5 Then 9.80
ElseIf val = 6 Then 10.00
ElseIf val = 7 Then 10.34
ElseIf val = 8 Then 10.96
ElseIf val = 9 Then 11.64
ElseIf val = 10 Then 12.41
End If
End Function
For the sake of simplicity I'm only listing through 10. I get all kinds of differnet errors while just trying to make this. Actually I'd love to be able to have either a separate sheet or workbook that could contain the data that a custom function could refer to for ease of maintaining but I haven't the foggiest if that is even possibly.
Thank you for any help and direction.
Sortosane