A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA user-defined worksheet function



 
 
Thread Tools Display Modes
  #1  
Old December 8th, 2003, 02:22 AM
Val
external usenet poster
 
Posts: n/a
Default VBA user-defined worksheet function

I wrote a VBA function that I want to use as a worksheet
function. The function supposes to convert degrees of
Fahrenheit into Celsius and, additionally, write in cell
A1 "Hello". As long as there is writing to A1 the function
gives #VALUE error. This is my code:

Function Celsius(fDegrees)
ActiveWorkbook.Sheets("Scheet1").Select
Sheets("Scheet1").Range("A1:A1").Text = "Hello"
Celsius = (fDegrees - 32) * 5 / 9
End Function

How to write it to make it work from the worksheet?

  #2  
Old December 8th, 2003, 02:32 AM
Peo Sjoblom
external usenet poster
 
Posts: n/a
Default VBA user-defined worksheet function

Val,

what is it you are trying to do? There is a function that can convert
already albeit
being a part of the Analysis ToolPak

=CONVERT(32,"F","C")

will convert 32 degrees Fahrenheit to Celsius..
Also note that neither built in functions nor add-ins can
populate another cell. If you explain what it is your are
doing I am sure someone could help you..

--

Regards,

Peo Sjoblom

"Val" wrote in message
...
I wrote a VBA function that I want to use as a worksheet
function. The function supposes to convert degrees of
Fahrenheit into Celsius and, additionally, write in cell
A1 "Hello". As long as there is writing to A1 the function
gives #VALUE error. This is my code:

Function Celsius(fDegrees)
ActiveWorkbook.Sheets("Scheet1").Select
Sheets("Scheet1").Range("A1:A1").Text = "Hello"
Celsius = (fDegrees - 32) * 5 / 9
End Function

How to write it to make it work from the worksheet?



  #3  
Old December 8th, 2003, 07:53 AM
Arvi Laanemets
external usenet poster
 
Posts: n/a
Default VBA user-defined worksheet function

Hi

Of course it's returning an error. You are changing contents of a cell in
function code - such an operation isn't allowed by definition. Even
selecting another cell isn't allowed. Any function mustn't change anything
on worksheet - not any values, or cursor position or whatever.


--
(When sending e-mail, use address )
Arvi Laanemets


"Val" wrote in message
...
I wrote a VBA function that I want to use as a worksheet
function. The function supposes to convert degrees of
Fahrenheit into Celsius and, additionally, write in cell
A1 "Hello". As long as there is writing to A1 the function
gives #VALUE error. This is my code:

Function Celsius(fDegrees)
ActiveWorkbook.Sheets("Scheet1").Select
Sheets("Scheet1").Range("A1:A1").Text = "Hello"
Celsius = (fDegrees - 32) * 5 / 9
End Function

How to write it to make it work from the worksheet?



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:50 PM.


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