Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default using functions

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default using functions

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default using functions

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default using functions

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert cell formula functions to code functions Adnan Excel Discussion (Misc queries) 1 October 1st 08 08:30 PM
formula/functions for average and if functions Petu71 Excel Worksheet Functions 2 August 5th 07 08:25 PM
efficiency: database functions vs. math functions vs. array formula nickname Excel Discussion (Misc queries) 2 July 14th 06 04:26 AM
Conversion from Spreadsheet Toolkit functions (ESSV....) to EssBase API functions sujay Excel Programming 0 June 5th 06 10:13 AM
excel functions and User defined functions Kanan Excel Programming 4 May 20th 04 11:21 PM


All times are GMT +1. The time now is 01:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"