Adding a worksheet function

Jook

New Member
Joined
Mar 19, 2002
Messages
22
I have added the function below to the workbook level of my VBA

Function Mileage(CostCentre)
' Checks for employees cost centre and subs correct one
Select Case CostCentre
Case "120.": Mileage = "130."
Case "220.": Mileage = "230."
Case "125.": Mileage = "130."
Case "225.": Mileage = "230."
Case "150.": Mileage = "140."
Case "250.": Mileage = "240."
End Select
End Function


The problem is that when I enter =Mileage(B4) in a cell, where B4 is the test valve, it returns #name? I have entered a simple function like:

Function user(user As String)
user = Application.UserName
End Function

And when I enter =User() in the cell I get #name? instead of my own name.

Any one know what I am doing wrong?

Thanks for any help.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Thanks

I knew it had to be something simple like that. That is the way it always is.
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top