Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I'm trying to undertand hpw to return a value from another function, when I run the mtest function I receive an error for the MsgBox (IsValidType) how I can I return a value? Thanks! Private Function IsValidType(ByVal sString) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function Sub mtest() myvar = "standarda" IsValidType myvar MsgBox (IsValidType) End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Sanjay,
Try something like: '============= Public Sub mTest() Dim res As Variant Dim myVar As String myVar = "standarda" res = IsValidType(myVar) MsgBox res End Sub '-------------- Private Function IsValidType(ByVal sString) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function '<<============= --- Regards, Norman "Sanjay" wrote in message ... Hi, I'm trying to undertand hpw to return a value from another function, when I run the mtest function I receive an error for the MsgBox (IsValidType) how I can I return a value? Thanks! Private Function IsValidType(ByVal sString) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function Sub mtest() myvar = "standarda" IsValidType myvar MsgBox (IsValidType) End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this:
Private Function IsValidType(sString As String) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function Sub mtest() Dim myvar As String myvar = "standarda" MsgBox IsValidType(myvar) End Sub Best is to put Option Explicit at the top of every module as that will force you to declare your variables. And do in the VBE: Tools, Options, Editor, tick Require variable declaration. RBS "Sanjay" wrote in message ... Hi, I'm trying to undertand hpw to return a value from another function, when I run the mtest function I receive an error for the MsgBox (IsValidType) how I can I return a value? Thanks! Private Function IsValidType(ByVal sString) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function Sub mtest() myvar = "standarda" IsValidType myvar MsgBox (IsValidType) End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Norman and RBS!
"Sanjay" wrote in message ... Hi, I'm trying to undertand hpw to return a value from another function, when I run the mtest function I receive an error for the MsgBox (IsValidType) how I can I return a value? Thanks! Private Function IsValidType(ByVal sString) As String If LCase(sString) = "standard" Then IsValidType = "SomethingA" Else IsValidType = "SomethingB" End If End Function Sub mtest() myvar = "standarda" IsValidType myvar MsgBox (IsValidType) End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to convert cell formula functions to code functions | Excel Discussion (Misc queries) | |||
formula/functions for average and if functions | Excel Worksheet Functions | |||
efficiency: database functions vs. math functions vs. array formula | Excel Discussion (Misc queries) | |||
Conversion from Spreadsheet Toolkit functions (ESSV....) to EssBase API functions | Excel Programming | |||
excel functions and User defined functions | Excel Programming |