Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,670
Default How to retrieve the value from formula?

The following function returns formula as a string, does anyone have any
suggestions on how to retrieve the value from formula and store into x and y
variable?

Working with an opened file under E:\dir\file.xls, I try to compare the
value under worksheet Table C3 & C4 for if statement.
Does anyone have any suggestions on how to make the code work?
Thank in advance for any suggestions
Eric

Sub Test
x = TheValue("E:\dir", "file.xls", "Table", "C3")
y = TheValue("E:\dir", "file.xls", "Table", "C4")
If x = y Then
MsgBox ("The value was " & y)
End If

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
TheValue = "[" & WorkbookName & "]" & Sheet & "'!" & Addr
End Function

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,339
Default How to retrieve the value from formula?

try:

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(WorkbookName)
If Err < 0 Then
Workbooks.Open Filename:=Path & WorkbookName
End If
TheValue = Workbooks(WorkbookName).Sheets(Sheet).Range(Addr). Value
End Function

"Eric" wrote:

The following function returns formula as a string, does anyone have any
suggestions on how to retrieve the value from formula and store into x and y
variable?

Working with an opened file under E:\dir\file.xls, I try to compare the
value under worksheet Table C3 & C4 for if statement.
Does anyone have any suggestions on how to make the code work?
Thank in advance for any suggestions
Eric

Sub Test
x = TheValue("E:\dir", "file.xls", "Table", "C3")
y = TheValue("E:\dir", "file.xls", "Table", "C4")
If x = y Then
MsgBox ("The value was " & y)
End If

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
TheValue = "[" & WorkbookName & "]" & Sheet & "'!" & Addr
End Function

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How to retrieve the value from formula?

Eric,

Try this:-

Sub Sistence()
Dim sourcewb As Workbook
Set sourcewb = Workbooks.Open("C:\book2.xls", False, False) '<===Change to
your path
x = sourcewb.Sheets("table").Range("C3").Value
y = sourcewb.Sheets("table").Range("C4").Value
If x = y Then
MsgBox ("The value was " & y)
End If
End Sub

"Eric" wrote:

The following function returns formula as a string, does anyone have any
suggestions on how to retrieve the value from formula and store into x and y
variable?

Working with an opened file under E:\dir\file.xls, I try to compare the
value under worksheet Table C3 & C4 for if statement.
Does anyone have any suggestions on how to make the code work?
Thank in advance for any suggestions
Eric

Sub Test
x = TheValue("E:\dir", "file.xls", "Table", "C3")
y = TheValue("E:\dir", "file.xls", "Table", "C4")
If x = y Then
MsgBox ("The value was " & y)
End If

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
TheValue = "[" & WorkbookName & "]" & Sheet & "'!" & Addr
End Function

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,670
Default Thank everyone ver much for suggestions

Thank everyone very much for suggestions
Eric

"Eric" wrote:

The following function returns formula as a string, does anyone have any
suggestions on how to retrieve the value from formula and store into x and y
variable?

Working with an opened file under E:\dir\file.xls, I try to compare the
value under worksheet Table C3 & C4 for if statement.
Does anyone have any suggestions on how to make the code work?
Thank in advance for any suggestions
Eric

Sub Test
x = TheValue("E:\dir", "file.xls", "Table", "C3")
y = TheValue("E:\dir", "file.xls", "Table", "C4")
If x = y Then
MsgBox ("The value was " & y)
End If

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
TheValue = "[" & WorkbookName & "]" & Sheet & "'!" & Addr
End Function

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22
Default How to retrieve the value from formula?

Eric,

If your workbook (file.xls) is already opened, you don't really need to pass
the path, so here is the modified function.

Function TheValue(WorkbookName, Sheet, Addr) As Variant
Dim cell As Range

Set cell = Workbooks(WorkbookName).Worksheets(Sheet).Range(Ad dr)
TheValue = cell.Value
End Function

HTH.

Cheers,
Socratis
"Eric" wrote:

The following function returns formula as a string, does anyone have any
suggestions on how to retrieve the value from formula and store into x and y
variable?

Working with an opened file under E:\dir\file.xls, I try to compare the
value under worksheet Table C3 & C4 for if statement.
Does anyone have any suggestions on how to make the code work?
Thank in advance for any suggestions
Eric

Sub Test
x = TheValue("E:\dir", "file.xls", "Table", "C3")
y = TheValue("E:\dir", "file.xls", "Table", "C4")
If x = y Then
MsgBox ("The value was " & y)
End If

Function TheValue(Path, WorkbookName, Sheet, Addr) As String
TheValue = "[" & WorkbookName & "]" & Sheet & "'!" & Addr
End Function

End Sub

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
Need formula to retrieve last non-blank cell in range Eric Excel Discussion (Misc queries) 7 July 20th 06 01:29 PM
Search and retrieve dziw Excel Discussion (Misc queries) 5 April 25th 06 09:50 PM
Formula to retrieve range of dates from a worksheet to calculate d accented Excel Worksheet Functions 0 January 10th 06 09:52 PM
retrieve cell formatting with IF(HLOOKUP) formula useR Excel Worksheet Functions 2 August 3rd 05 06:55 PM
Retrieve data Matt W via OfficeKB.com Excel Discussion (Misc queries) 1 July 14th 05 06:40 PM


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