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

Hello,

I have a formula foo which is used in a worksheet as =foo(A1:A10)
and it is defined in a module as

Public Function foo(ByRef data As Range) As Double

There I would like to do some visual formatting on the data such as

data.select
data.font.colorindex = 3

But there is no reaction. Is there something I have misunderstood
about passing variables to custom functions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ByRef strangeness

Functions used in a worksheet are not permitted to alter the excel
environment (such as formatting) or change the value of other cells. They
can only return a value to the cell in which they are used.

--
Regards,
Tom Ogilvy

"Nicklas Karlsson" wrote in message
m...
Hello,

I have a formula foo which is used in a worksheet as =foo(A1:A10)
and it is defined in a module as

Public Function foo(ByRef data As Range) As Double

There I would like to do some visual formatting on the data such as

data.select
data.font.colorindex = 3

But there is no reaction. Is there something I have misunderstood
about passing variables to custom functions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default ByRef strangeness

Nicklas

XL UDFs can only pass back values, they cannot change objects. You use Subs
for this

eg

Sub Foo()
.......do any changes here
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Nicklas Karlsson" wrote in message
m...
Hello,

I have a formula foo which is used in a worksheet as =foo(A1:A10)
and it is defined in a module as

Public Function foo(ByRef data As Range) As Double

There I would like to do some visual formatting on the data such as

data.select
data.font.colorindex = 3

But there is no reaction. Is there something I have misunderstood
about passing variables to custom functions?



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
byref errors Ryan H. Excel Programming 12 August 4th 04 04:44 PM
More HpageBreaks Strangeness BillzyBop Excel Programming 0 June 23rd 04 03:40 AM
ByRef question Tommy Flynn[_2_] Excel Programming 2 November 12th 03 01:35 PM
ByRef not passing address Ian Stanborough Excel Programming 3 October 30th 03 01:30 PM
Is ByVal always better if ByRef isn't necessary Jeff[_17_] Excel Programming 5 July 25th 03 09:25 AM


All times are GMT +1. The time now is 01:58 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"