Rachel-- Try something like the following: Function Discount(Customer_Type As String, Quantity_of_bks As Integer) If Customer_Type = "Individual" Select Case Quantity_of_bks Case < 5 Discount = 0 Case Between 5 And 24 Discount = 0.15 Case Else ' If Quantity_of_bks is >= 25 Discount = 0.25 Else ' if Customer_Type is NOT "Individual" Select Case Quantity_of_bks Case < 5 Discount = 0.05 Case Between 5 And 14 Discount = 0.1 Case Between 15 And 24 Discount = 0.15 Case Between 25 And 49 Discount = 0.2 Case Else ' If Quantity_of_bks is => 50 Discount = 0.3 End Select End If End Function In the function you submitted, you don 't have enough closing 'End If' statements; you need one for each 'If' statement, of course. (Please note that the code snipped above was not parsed through the Visual Basic editor, so it may contain syntax or other errors; please double check.) -----Original Message----- From: mso-bounce@xxxxxxxxxxxxx [mailto:mso-bounce@xxxxxxxxxxxxx] On Behalf Of Rachel Jobes Sent: Thursday, July 12, 2007 3:10 PM To: mso@xxxxxxxxxxxxx Subject: [mso] Visual Basic in Excel Hi All I am just trying to write my first bit of VBA and have found it quite easy however I have then come to input the formula in my cell and it doesnt work. I have created a lot of variations within the VBA saving each version but I always get a error usually #REF #VALUE or #NAME - when these appear I use the excel help with no avail. My spreadsheet is customer type column b and quanitity of books column c My function / formulae is being entered into column D = Discount (B4,C4) My VBA forst draft is below... Function Discount(Customer_Type As String, Quantity_of_bks As Integer) If Customer_Type = "Individual" And Quantity_of_bks < 5 Then Discount = 0# If Quantity_of_bks >= 5 And Quantity_of_bks < 24 Then Discount = 0.15 If Quantity_of_bks > 25 Then Discount = 0.25 ElseIf Quanitity_of_bks < 5 Then Discount = 0.05 If Quanitity_of_bks >= 5 < 14 Then Discount = 0.1 If Quantity_of_bks >= 15 < 24 Then Discount = 0.15 If Quantity_of_bks >= 25 < 49 Then Discount = 0.2 If Quantity_of_bks > 50 Then Discount = 0.3 End If End Function Things I have tried include an End IF after the first IF and an END If at after every line I have also tried writing in the other customer types options so instead of having an Else IF I have another IF e.g. If Customer_Type = "Educational Inst" or "Library" or "School" And ....... Nothing seemed to create a result when the function is input in the cell. I am not sure whether my VBA is incorrect or the Formulae. I dont even mind if I get an incorrect answer I can amend the VBA but I cant get past the errors. Can anyone help? Thanks Rache ************************************************************* You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or MicrosoftOffice@xxxxxxxxxxxxxxxx To send mail to the group, simply address it to mso@xxxxxxxxxxxxx To Unsubscribe from this group, visit the group's homepage and use the dropdown menu at the top. This will allow you to unsubscribe your email address or change your email settings to digest or vacation (no mail). //www.freelists.org/webpage/mso To be able to share files with the group, you must join our Yahoo sister group. This group will not allow for posting of emails, but will allow you to join and share problem files, templates, etc.: http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE SHARING ONLY. If you are using Outlook and you see a lot of unnecessary code in your email messages, read these instructions that explain why and how to fix it: http://personal-computer-tutor.com/abc3/v28/greg28.htm ************************************************************* No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.4/897 - Release Date: 7/11/2007 9:57 PM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.4/897 - Release Date: 7/11/2007 9:57 PM ************************************************************* You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or MicrosoftOffice@xxxxxxxxxxxxxxxx To send mail to the group, simply address it to mso@xxxxxxxxxxxxx To Unsubscribe from this group, visit the group's homepage and use the dropdown menu at the top. This will allow you to unsubscribe your email address or change your email settings to digest or vacation (no mail). //www.freelists.org/webpage/mso To be able to share files with the group, you must join our Yahoo sister group. This group will not allow for posting of emails, but will allow you to join and share problem files, templates, etc.: http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE SHARING ONLY. If you are using Outlook and you see a lot of unnecessary code in your email messages, read these instructions that explain why and how to fix it: http://personal-computer-tutor.com/abc3/v28/greg28.htm *************************************************************