Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / December 2005

Tip: Looking for answers? Try searching our database.

Changing Formula elements to values

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Co-op Bank - 15 Dec 2005 10:27 GMT
Hello, is there a way to change a formula for example '=a1+a2+a3' to show its
constant values instead in the cell so it would show '=10+20+30' assuming
'a1' = 10 etc...

Would this be a VBA solution? Any help suggestions would be much appreciated.

Regards
Brian
Manchester, England
Gary''s Student - 15 Dec 2005 14:30 GMT
Yes, it can be done in VBA:

1. Either code or down-load a simple table-driven parser for worksheet
constructs.
2. Run the parser on any cell to develop a table of cell references,
constants, named objects, etc.
3. Use the EVALUATE method on each item in the list to get the numeric value
4. Replace each item in the original expression with its equivalent numeric
value
5. Store the modified expression elsewhere.
Signature

Gary's Student

> Hello, is there a way to change a formula for example '=a1+a2+a3' to show its
> constant values instead in the cell so it would show '=10+20+30' assuming
[quoted text clipped - 5 lines]
> Brian
> Manchester, England
Bernie Deitrick - 15 Dec 2005 14:47 GMT
Brian,

Select the cell with the formula, and run the macro below.  It will change most cell references to
values, with the exception of multi-cell ranges.  That would be do-able, but would require a
re-write.

HTH,
Bernie
MS Excel MVP

Sub Convert()
'Converts cell references to values within the
'Activecell's formula
'Written by Bernie Deitrick Dec 15, 2005

Dim strForm As String
Dim strOrig As String
Dim Addr As Variant
Dim i As Integer
Dim myCell As Range
Const Operators As String = "=+-*/^()"

strForm = ActiveCell.Formula
strOrig = ActiveCell.Formula

For i = 1 To Len(Operators)
strForm = Replace(strForm, Mid(Operators, i, 1), "*")
Next i

Addr = Split(strForm, "*")
For i = LBound(Addr) To UBound(Addr)
On Error GoTo NotCell
Set myCell = Range(Addr(i))
strOrig = Replace(strOrig, Addr(i), myCell.Value)
NotCell:
Resume GoOn
GoOn:
Next i

ActiveCell.Formula = strOrig
End Sub

> Hello, is there a way to change a formula for example '=a1+a2+a3' to show its
> constant values instead in the cell so it would show '=10+20+30' assuming
[quoted text clipped - 5 lines]
> Brian
> Manchester, England
Co-op Bank - 18 Dec 2005 15:51 GMT
Excellent answer Bernie thankyou, this has saved alot of time.

Thanks
Brian

> Brian,
>
[quoted text clipped - 47 lines]
> > Brian
> > Manchester, England
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.