Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I need to create a function in VBA Excel.
The code is like this Function mysub(x as variant) as variant ..................... code goes here ............... end function Now if the user enters code mysub(somestring) or something like that then there is a error message in the Excel Cell But, I want to get the excel cell not to display such error. I tried to get the type but it didn't work fine My code goes like this. Function newfun(agrus As Variant) As Variant Dim x As Variant newfun = argus * agrus Exit Function 'If IsMissing(argus) Then 'newfun = argus & "No argument in the function" 'Else x = TypeName(argus) Select Case x Case "Range" newfun = argus & "Cannot take range as argument. Enter Single cell value" Case "Null" newfun = argus & "You didn't entered an argument. Must have one argument." Case "Error" newfun = argus & "You entered a error value. Check the value." Case "Boolean" newfun = argus & "You entered boolean value." Case "Empty" newfun = argus & "Empty value." Case Else newfun = argus & "Other data types. " & TypeName(argus) End Select 'End If 'newfun = argus & "No you can make a start" 'End If End Function Can anyone help |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Get rid of the 'Exit Function' line or try something like...
'/--------------------------------------- Function newfun(argus As Variant) As Variant Dim x As Variant On Error GoTo err_Function newfun = argus * argus exit_Function: On Error Resume Next Exit Function err_Function: newfun = Null GoTo exit_Function End Function '/--------------------------------------- -- Hope this helps. If it does, please click the Yes button. Thanks in advance for your feedback. Gary Brown "Subodh" wrote: I need to create a function in VBA Excel. The code is like this Function mysub(x as variant) as variant ..................... code goes here ............... end function Now if the user enters code mysub(somestring) or something like that then there is a error message in the Excel Cell But, I want to get the excel cell not to display such error. I tried to get the type but it didn't work fine My code goes like this. Function newfun(agrus As Variant) As Variant Dim x As Variant newfun = argus * agrus Exit Function 'If IsMissing(argus) Then 'newfun = argus & "No argument in the function" 'Else x = TypeName(argus) Select Case x Case "Range" newfun = argus & "Cannot take range as argument. Enter Single cell value" Case "Null" newfun = argus & "You didn't entered an argument. Must have one argument." Case "Error" newfun = argus & "You entered a error value. Check the value." Case "Boolean" newfun = argus & "You entered boolean value." Case "Empty" newfun = argus & "Empty value." Case Else newfun = argus & "Other data types. " & TypeName(argus) End Select 'End If 'newfun = argus & "No you can make a start" 'End If End Function Can anyone help . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Obtaining the minimum of values which have been generated by a for | New Users to Excel | |||
OnError - what generated the error? | Excel Programming | |||
Sorting values generated by a formula... | Excel Discussion (Misc queries) | |||
How do I use ISERROR in functions to hide error values | Excel Worksheet Functions | |||
accumulating values generated daily | Excel Worksheet Functions |