if function Macro not working

blzalewski

New Member
Joined
Jun 22, 2007
Messages
4
Can anybody tell me why this function is not working:

Function CalcValue(pVal As String) As Long

If pVal = "xy1267" Then
CalcValue = "fdsfs, dfs"

ElseIf pVal = "xy1671" Then
CalcValue = "xxx, ysdf"

ElseIf pVal = "me2742" Then
CalcValue = "asdfsa, dsf"

ElseIf pVal = "qw1352" Then
CalcValue = "asda, asdf"

ElseIf pVal = "po7571" Then
CalcValue = "sada, asdas"

ElseIf pVal = "qw3127" Then
CalcValue = "asda, asdasda"

ElseIf pVal = "qw9898" Then
CalcValue = "sda,fsdsd"

ElseIf pVal = "sd2458" Then
CalcValue = "sadro, sdlis"

ElseIf pVal = "bq9632" Then
CalcValue = "sdada, sad"

ElseIf pVal = "gc2536" Then
CalcValue = "sdaf, sdaas"

ElseIf pVal = "pp8187" Then
CalcValue = "qw, sda"

Else
CalcValue = "ERROR: Not in CalcValue IF list"
End If

End Function
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Whats not working? Are you always getting the ERROR message in the if?

You have the function defined as a long when you are trying to return a string?

Change:

Code:
Function CalcValue(pVal As String) As Long
To:

Code:
Function CalcValue(pVal As String) As String
Hope that helps.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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