Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem with UDF can't return the value of a formula

Hi, I'm new to UDF but not VBA.

I'm trying to take the value from cell A and copy it over to cell B.

-The value in cell A is a formula that generates a formula.
example cell A value: ="=sum(200)"
the actual formula is more complicated than this however this is the
main idea for the sake of keeping it simple.

-The UDF looks like this:

Function calculateThis(Cell_A As Range)
calculateThis = Cell_A.Value
End Function

i've also tryed
calculateThis = Cell_A.formula
calculateThis.value = Cell_A.formula (this one just stops the code
execution)


-Cell B looks like this: = calculateThis(A1)

-the result i get is: =sum(200)

-the result i need is: 200

i need to get the answer and not the formula.

I kind of know what's happening but not sure how to fix it.

I hope my explanation was okay, any help would be appreciated.
thank you
Bilal
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Problem with UDF can't return the value of a formula

Maybe:

Option Explicit
Function calculateThis(Cell_A As Range)
calculateThis = Evaluate(Cell_A.Value)
End Function


Billy wrote:

Hi, I'm new to UDF but not VBA.

I'm trying to take the value from cell A and copy it over to cell B.

-The value in cell A is a formula that generates a formula.
example cell A value: ="=sum(200)"
the actual formula is more complicated than this however this is the
main idea for the sake of keeping it simple.

-The UDF looks like this:

Function calculateThis(Cell_A As Range)
calculateThis = Cell_A.Value
End Function

i've also tryed
calculateThis = Cell_A.formula
calculateThis.value = Cell_A.formula (this one just stops the code
execution)

-Cell B looks like this: = calculateThis(A1)

-the result i get is: =sum(200)

-the result i need is: 200

i need to get the answer and not the formula.

I kind of know what's happening but not sure how to fix it.

I hope my explanation was okay, any help would be appreciated.
thank you
Bilal


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem with UDF can't return the value of a formula

Thanks Dave... that worked :)

Dave Peterson wrote in message ...
Maybe:

Option Explicit
Function calculateThis(Cell_A As Range)
calculateThis = Evaluate(Cell_A.Value)
End Function


Billy wrote:

Hi, I'm new to UDF but not VBA.

I'm trying to take the value from cell A and copy it over to cell B.

-The value in cell A is a formula that generates a formula.
example cell A value: ="=sum(200)"
the actual formula is more complicated than this however this is the
main idea for the sake of keeping it simple.

-The UDF looks like this:

Function calculateThis(Cell_A As Range)
calculateThis = Cell_A.Value
End Function

i've also tryed
calculateThis = Cell_A.formula
calculateThis.value = Cell_A.formula (this one just stops the code
execution)

-Cell B looks like this: = calculateThis(A1)

-the result i get is: =sum(200)

-the result i need is: 200

i need to get the answer and not the formula.

I kind of know what's happening but not sure how to fix it.

I hope my explanation was okay, any help would be appreciated.
thank you
Bilal

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem with UDF can't return the value of a formula

Hi, that did work for the simple example like:

calculateThis = Evaluate("=sum(1+1)")

however when i try to use this solution to evaluate a formula that
refrences another workbook like this:

calculateThis = Evaluate("='C:\[book1.xls]Sheet1'!$A$1")

....It returnes error 2023


question #2
also another thing i noticed with UDF's that i can't explain is when i
try to say rangeA.value = rangeX.value the code simply stops and i
have no idea why no error message or anything.

Thank you
Bilal






Dave Peterson wrote in message ...
Maybe:

Option Explicit
Function calculateThis(Cell_A As Range)
calculateThis = Evaluate(Cell_A.Value)
End Function


Billy wrote:

Hi, I'm new to UDF but not VBA.

I'm trying to take the value from cell A and copy it over to cell B.

-The value in cell A is a formula that generates a formula.
example cell A value: ="=sum(200)"
the actual formula is more complicated than this however this is the
main idea for the sake of keeping it simple.

-The UDF looks like this:

Function calculateThis(Cell_A As Range)
calculateThis = Cell_A.Value
End Function

i've also tryed
calculateThis = Cell_A.formula
calculateThis.value = Cell_A.formula (this one just stops the code
execution)

-Cell B looks like this: = calculateThis(A1)

-the result i get is: =sum(200)

-the result i need is: 200

i need to get the answer and not the formula.

I kind of know what's happening but not sure how to fix it.

I hope my explanation was okay, any help would be appreciated.
thank you
Bilal

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Problem with UDF can't return the value of a formula

First, functions called from worksheet formulas can't update other cells.

They can return something to the cell with the function.

=calculatethis()
worked for me if the other workbook was open. But not if that other workbook
was closed.

If you want to retrieve a value from a closed workbook in VBA, you can use one
of the techniques at John Walkenbach's site:

http://j-walk.com/ss/excel/eee/eee009.txt
Look for either: GetDataFromClosedFile or GetValue.

If you want to retrieve a value from a closed workbook from a worksheet cell,
you could use a UDF that Harlan Grove wrote:

http://www.google.com/groups?selm=hk...wsranger.c om

You may have to parse your value to pass it to Harlan's UDF, though.

Billy wrote:

Hi, that did work for the simple example like:

calculateThis = Evaluate("=sum(1+1)")

however when i try to use this solution to evaluate a formula that
refrences another workbook like this:

calculateThis = Evaluate("='C:\[book1.xls]Sheet1'!$A$1")

...It returnes error 2023

question #2
also another thing i noticed with UDF's that i can't explain is when i
try to say rangeA.value = rangeX.value the code simply stops and i
have no idea why no error message or anything.

Thank you
Bilal

Dave Peterson wrote in message ...
Maybe:

Option Explicit
Function calculateThis(Cell_A As Range)
calculateThis = Evaluate(Cell_A.Value)
End Function


Billy wrote:

Hi, I'm new to UDF but not VBA.

I'm trying to take the value from cell A and copy it over to cell B.

-The value in cell A is a formula that generates a formula.
example cell A value: ="=sum(200)"
the actual formula is more complicated than this however this is the
main idea for the sake of keeping it simple.

-The UDF looks like this:

Function calculateThis(Cell_A As Range)
calculateThis = Cell_A.Value
End Function

i've also tryed
calculateThis = Cell_A.formula
calculateThis.value = Cell_A.formula (this one just stops the code
execution)

-Cell B looks like this: = calculateThis(A1)

-the result i get is: =sum(200)

-the result i need is: 200

i need to get the answer and not the formula.

I kind of know what's happening but not sure how to fix it.

I hope my explanation was okay, any help would be appreciated.
thank you
Bilal


--

Dave Peterson

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
Carriage Return Problem Don L[_2_] Excel Discussion (Misc queries) 1 March 12th 10 07:04 PM
if formula return Theresa Excel Discussion (Misc queries) 4 September 16th 08 03:53 PM
Return Last Value in a Row formula Txlonghorn76 Excel Worksheet Functions 5 September 4th 08 10:55 PM
Problem with message box return value John Baker Excel Programming 3 July 2nd 04 08:53 PM
Function Problem.... Return Value Schrades Excel Programming 3 November 12th 03 08:33 PM


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