#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,358
Default UDF help

What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


--
John C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default UDF help

It is quite simple.

The value is returned as the function name

Function NullCell()

'some code
NullCell = somevalue
End Function

If you want to pass a value into the function you just declare an argument

Function NullCell(ByRef rng As Range)

'do something to rng
NullCell = somevalue
End Function

--
__________________________________
HTH

Bob

"John C" <johnc@stateofdenial wrote in message
...
What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a
basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


--
John C



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default UDF help

Some of the basics of UDFs are described at
http://www.cpearson.com/Excel/Writin...ionsInVBA.aspx


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"John C" <johnc@stateofdenial wrote in message
...
What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a
basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


--
John C


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default UDF help

On Wed, 6 Aug 2008 12:02:01 -0700, John C <johnc@stateofdenial wrote:

What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


For the basic situation you can try the following UDF:

Function NullCell(r As Range) As Variant
If r.Value = "" Then
NullCell = ""
Else
NullCell = r.Value
End If
End Function

Hope this helps / Lars-Åke
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,358
Default UDF help

Not quite as simple as that. I wish it were.
If A1 is either blank or empty, I want the cell where the NullCell function
is to appear empty.
If A1 is blank due to formula (i.e.: =""), then the NullCell function works,
but if there is NO data in there, I get an answer of 0.
--
John C


"Bob Phillips" wrote:

It is quite simple.

The value is returned as the function name

Function NullCell()

'some code
NullCell = somevalue
End Function

If you want to pass a value into the function you just declare an argument

Function NullCell(ByRef rng As Range)

'do something to rng
NullCell = somevalue
End Function

--
__________________________________
HTH

Bob

"John C" <johnc@stateofdenial wrote in message
...
What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a
basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


--
John C






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,358
Default UDF help

I come up with #VALUE! errors, no matter when tested. static text, static
number, formulated text, formulated number, empty cell by formula, empty cell
because it's just empty.
--
John C


"Lars-Ã…ke Aspelin" wrote:

On Wed, 6 Aug 2008 12:02:01 -0700, John C <johnc@stateofdenial wrote:

What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


For the basic situation you can try the following UDF:

Function NullCell(r As Range) As Variant
If r.Value = "" Then
NullCell = ""
Else
NullCell = r.Value
End If
End Function

Hope this helps / Lars-Ã…ke

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default UDF help

On Wed, 06 Aug 2008 19:47:00 GMT, Lars-Åke Aspelin
wrote:

On Wed, 6 Aug 2008 12:02:01 -0700, John C <johnc@stateofdenial wrote:

What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


For the basic situation you can try the following UDF:

Function NullCell(r As Range) As Variant
If r.Value = "" Then
NullCell = ""
Else
NullCell = r.Value
End If
End Function

Hope this helps / Lars-Åke


Or why not just like this:

Function NullCell(r As Range) As Variant
NullCell = r.Value
End Function

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default UDF help

On Wed, 06 Aug 2008 20:14:45 GMT, Lars-Åke Aspelin
wrote:

On Wed, 06 Aug 2008 19:47:00 GMT, Lars-Åke Aspelin
wrote:

On Wed, 6 Aug 2008 12:02:01 -0700, John C <johnc@stateofdenial wrote:

What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give a basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


For the basic situation you can try the following UDF:

Function NullCell(r As Range) As Variant
If r.Value = "" Then
NullCell = ""
Else
NullCell = r.Value
End If
End Function

Hope this helps / Lars-Åke


Or why not just like this:

Function NullCell(r As Range) As Variant
NullCell = r.Value
End Function


No, that did not work. back to my first proposal:

Function NullCell(r As Range) As Variant
If r.Value = "" Then
NullCell = ""
Else
NullCell = r.Value
End If
End Function
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default UDF help

#VALUE will be the result e.g. if you have not the same spelling of r
in (r as Range) and in r.Value

To me the function work as expected for all cases you mention.

Lars-Åke

On Wed, 6 Aug 2008 13:11:03 -0700, John C <johnc@stateofdenial wrote:

I come up with #VALUE! errors, no matter when tested. static text, static
number, formulated text, formulated number, empty cell by formula, empty cell
because it's just empty.




  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,345
Default UDF help

You're very welcome.

--

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"John C" <johnc@stateofdenial wrote in message
...
Thank you very much.
--
John C


"Sandy Mann" wrote:

Try something like:

Function NullCell(rng As Range) As Variant
If rng.Value = "" Then
NullCell = ""
Exit Function
End If
NullCell = rng.Value
End Function


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"John C" <johnc@stateofdenial wrote in message
...
Not quite as simple as that. I wish it were.
If A1 is either blank or empty, I want the cell where the NullCell
function
is to appear empty.
If A1 is blank due to formula (i.e.: =""), then the NullCell function
works,
but if there is NO data in there, I get an answer of 0.
--
John C


"Bob Phillips" wrote:

It is quite simple.

The value is returned as the function name

Function NullCell()

'some code
NullCell = somevalue
End Function

If you want to pass a value into the function you just declare an
argument

Function NullCell(ByRef rng As Range)

'do something to rng
NullCell = somevalue
End Function

--
__________________________________
HTH

Bob

"John C" <johnc@stateofdenial wrote in message
...
What are some good references on creating UDF's?

While my real need is far more complex than I list here, I will give
a
basic
basic situation.
A2: =IF(A1="","",A1)

I would prefer something more like
A2: =NullCell(A1)

Thank you.


--
John C










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



All times are GMT +1. The time now is 07:46 PM.

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"