VBA Function Returns #VALUE!, Works When Ran Via Editor.

Troy1

Board Regular
Joined
Jul 2, 2014
Messages
149
Hello,


I am trying to run the below function, the code itself executes without errors when I manually run it via the VBA editor. When I enter the function into the cell =EXSMSNG() it returns #VALUE!. Any clue what I am doing wrong? I am new to functions. :(



Code:
Function EXSMSNG()

Dim relCell As String


relCell = ActiveCell.Offset(rowOffset:=0, columnOffset:=-1).Address(RowAbsolute:=False, ColumnAbsolute:=False)


ActiveCell.Formula = "=IF(COUNTIFS(Sheet2!B:B," & relCell & ",Sheet2!F:F,""N"")=1,""No appointment requested on BOL."",IF(COUNTIFS(Sheet2!B:B," & relCell & ",Sheet2!F:F,""Y"",Sheet2!AC:AC,0)=1,""Operations did not set appointment."",""Missed appointment.""))"




End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
A funnction cannot return a formula - take a look at
Writing Your Own Functions In VBA

Where in Simple User Defined Function you can see
"A UDF an only return a value..."

As an alternative you can use Evaluate (observe the double-quotes in red - they are necessary because relCell is a String)

Code:
Function EXSMSNG()
Dim relCell As String

relCell = ActiveCell.Offset(rowOffset:=0, columnOffset:=-1).Address(RowAbsolute:=False, ColumnAbsolute:=False)

EXSMSNG = Evaluate( _
    "=IF(COUNTIFS(Sheet2!B:B,[COLOR=#ff0000]""[/COLOR]" & relCell & _
        [COLOR=#ff0000]""[/COLOR]",Sheet2!F:F,""N"")=1,""No appointment requested on BOL."",IF(COUNTIFS(Sheet2!B:B,[COLOR=#ff0000]""[/COLOR]" & _
        relCell & "[COLOR=#ff0000]""[/COLOR],Sheet2!F:F,""Y"",Sheet2!AC:AC,0)=1,""Operations did not set appointment."",""Missed appointment.""))")

End Function

Hope this helps

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

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