Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Newbie question - regarding function parameters

Hello Folks,

i want to write a function, to call from my Excelsheets.
As param i want to pass either a String or a Cellreference on a Cell
containing the string.

Do i have to declare the param in functionsheader as variant?
If so, how can i check if it is a Cellreference or a String?

I would be glad to get any hint on, where to look and read in OH or
other material.

Greetings,
Thomas
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Newbie question - regarding function parameters

Public Function myfunction(var As Variant) As String
Dim str As String

If TypeOf var Is Range Then
str = "Is Range"
ElseIf VarType(var) = vbString Then
str = "Is String"
Else
str = "is something else"
End If

myfunction = str
End Function


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Thomas Söhne" wrote in message
...
Hello Folks,

i want to write a function, to call from my Excelsheets.
As param i want to pass either a String or a Cellreference on a Cell
containing the string.

Do i have to declare the param in functionsheader as variant?
If so, how can i check if it is a Cellreference or a String?

I would be glad to get any hint on, where to look and read in OH or other
material.

Greetings,
Thomas



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Newbie question - regarding function parameters

There is nothing wrong with what Rob writes, but if you just what to use the
parameter value, you don't have to test it

Function Test(var As Variant)
Test = var
End Function

Of course, if you want to do more than that, you might want to. For
instance, you might want to ensure that the range, if it is a range, only
includes one cell

Public Function myfunction(var As Variant) As String
Dim str As String

If TypeOf var Is Range Then
If var.Count 1 Then
myfunction = CVErr(xlErrRef)
Else
str = "Is Range"
End If
ElseIf VarType(var) = vbString Then
str = "Is String"
Else
str = "is something else"
End If

myfunction = str
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rob van Gelder" wrote in message
...
Public Function myfunction(var As Variant) As String
Dim str As String

If TypeOf var Is Range Then
str = "Is Range"
ElseIf VarType(var) = vbString Then
str = "Is String"
Else
str = "is something else"
End If

myfunction = str
End Function


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Thomas Söhne" wrote in message
...
Hello Folks,

i want to write a function, to call from my Excelsheets.
As param i want to pass either a String or a Cellreference on a Cell
containing the string.

Do i have to declare the param in functionsheader as variant?
If so, how can i check if it is a Cellreference or a String?

I would be glad to get any hint on, where to look and read in OH or

other
material.

Greetings,
Thomas





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Newbie question - regarding function parameters

Hello Rob and Bob,

thank you for your hints.

It is exactly what i was searching, i will be able to do my task with
your help.

so long,
regards
Thomas
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
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
Parameters question TR Excel Worksheet Functions 5 October 23rd 06 09:17 PM
Newbie Question, NOW() function justin4480 Excel Worksheet Functions 3 May 29th 06 10:31 PM
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Newbie question: function call wachen Excel Programming 1 September 24th 04 07:05 PM


All times are GMT +1. The time now is 03:19 AM.

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

About Us

"It's about Microsoft Excel"