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 fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Jook

New Member
Joined
Mar 19, 2002
Messages
22
Thanks

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

Forum statistics

Threads
1,144,733
Messages
5,725,981
Members
422,652
Latest member
Elnene1

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
Top