Jess Rulz
04-04-2008, 01:48 AM
Hi
My name is Rebecca and i am new to the forum and VBA. i have been learning it at uni for a couple of weeks and habe my first project due next week. We have been give the task to create a user defined function that can:
"Calculate the cost of buying Easter Eggs, where a larger discount is applied as you purchase more eggs… up to a maximum discount rate. Boxes to carry the eggs are charged extra, but a discount will be applied for purchases of a certain size"
I have a code as shown below but when i try and use it in excel it says that " this code takes no arguments"
i have tried to edit the function but i have had no luck getting it to work. i would appriciate it very much if someone could look at it and tell me how i can correct it. Many thanks in advance.
Rebecca
My code
Option Explicit
Public Function EasterEggs(intNumberEggs As Integer) As Integer
EasterEggs = intNumberEggs * 4
'The above calculates the cost of the easter eggs
End Function
Public Function DiscountEggs(intNumberEggs As Integer) As String
Dim strDiscount As String
If intNumberEggs < 10 Then
strDiscount = "No Discount"
Else
If intNumberEggs < 12 Then
strDiscount = "E"
Else
If intNumberEggs < 14 Then
strDiscount = "D"
Else
If intNumberEggs < 16 Then
strDiscount = "C"
Else
If intNumberEggs < 18 Then
strDiscount = "B"
Else
If intNumberEggs < 20 Then
strDiscount = "A"
End If
End If
End If
End If
End If
End If
'above is an If calcualtion which calculates the discount awarded to
'customers depending on the size of their purchase
DiscountEggs = strDiscount
End Function
Public Function BoxesCost(intNumberBoxes As Integer) As Integer
BoxesCost = intNumberBoxes * 2
'The above calculates the cost of the boxes for the easter eggs
End Function
Public Function BoxesDiscount(intNumberBoxes As Integer) As String
Dim strBoxDiscount As String
If intNumberBoxes < 2 Then
strBoxDiscount = "No Discount"
Else
If intNumberBoxes < 4 Then
strBoxDiscount = "E"
Else
If intNumberBoxes < 6 Then
strBoxDiscount = "D"
Else
If intNumberBoxes < 8 Then
strBoxDiscount = "C"
Else
If intNumberBoxes < 10 Then
strBoxDiscount = "B"
Else
If intNumberBoxes < 12 Then
strBoxDiscount = "A"
End If
End If
End If
End If
End If
End If
'above is an If calcualtion which calculates the discount awarded
'to customers depending on the size of their purchase of Boxes for Easter Eggs.
BoxesDiscount = strBoxDiscount
End Function
Edited by Aussiebear to include the last three lines within the vba tags
Edited By Simon Lloyd to make code window smaller easier to read
My name is Rebecca and i am new to the forum and VBA. i have been learning it at uni for a couple of weeks and habe my first project due next week. We have been give the task to create a user defined function that can:
"Calculate the cost of buying Easter Eggs, where a larger discount is applied as you purchase more eggs… up to a maximum discount rate. Boxes to carry the eggs are charged extra, but a discount will be applied for purchases of a certain size"
I have a code as shown below but when i try and use it in excel it says that " this code takes no arguments"
i have tried to edit the function but i have had no luck getting it to work. i would appriciate it very much if someone could look at it and tell me how i can correct it. Many thanks in advance.
Rebecca
My code
Option Explicit
Public Function EasterEggs(intNumberEggs As Integer) As Integer
EasterEggs = intNumberEggs * 4
'The above calculates the cost of the easter eggs
End Function
Public Function DiscountEggs(intNumberEggs As Integer) As String
Dim strDiscount As String
If intNumberEggs < 10 Then
strDiscount = "No Discount"
Else
If intNumberEggs < 12 Then
strDiscount = "E"
Else
If intNumberEggs < 14 Then
strDiscount = "D"
Else
If intNumberEggs < 16 Then
strDiscount = "C"
Else
If intNumberEggs < 18 Then
strDiscount = "B"
Else
If intNumberEggs < 20 Then
strDiscount = "A"
End If
End If
End If
End If
End If
End If
'above is an If calcualtion which calculates the discount awarded to
'customers depending on the size of their purchase
DiscountEggs = strDiscount
End Function
Public Function BoxesCost(intNumberBoxes As Integer) As Integer
BoxesCost = intNumberBoxes * 2
'The above calculates the cost of the boxes for the easter eggs
End Function
Public Function BoxesDiscount(intNumberBoxes As Integer) As String
Dim strBoxDiscount As String
If intNumberBoxes < 2 Then
strBoxDiscount = "No Discount"
Else
If intNumberBoxes < 4 Then
strBoxDiscount = "E"
Else
If intNumberBoxes < 6 Then
strBoxDiscount = "D"
Else
If intNumberBoxes < 8 Then
strBoxDiscount = "C"
Else
If intNumberBoxes < 10 Then
strBoxDiscount = "B"
Else
If intNumberBoxes < 12 Then
strBoxDiscount = "A"
End If
End If
End If
End If
End If
End If
'above is an If calcualtion which calculates the discount awarded
'to customers depending on the size of their purchase of Boxes for Easter Eggs.
BoxesDiscount = strBoxDiscount
End Function
Edited by Aussiebear to include the last three lines within the vba tags
Edited By Simon Lloyd to make code window smaller easier to read