LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,059
Default Dana: help with your Demo() macro to "expand" formulas

Dana (and other VBA experts),

In the thread "Expanding Formulas", you offered the macro below as a
(great!) starting point. I made some minor modifications.

The Replace() operation seems to make the appropriate substitution
only for relative references of the form B1. For example, absolute
references of the form $B$1 are not replaced.

The root cause of the problem seems to be that p.Address(false,false)
always returns a relative reference, even if the original reference is
absolute. I presume that the Replace() operation is ineffective
because "B1" does not match "$B$1" in the formula.

Changing things to p.Address(true,true) rectifies that; but of course,
then relative references are not substituted.

Can the macro be changed easily to substitute all forms of references?

The modified macro:

Sub Demo()
Dim s, p, a, v
Dim cell

Debug.Print "-----------"
For Each cell In Selection
s = cell.Formula
Debug.Print s
On Error Resume Next
p = cell.Precedents
If Err = 0 Then
For Each p In cell.Precedents
a = p.Address(False, False)
v = p.Value
s = Replace(s, a, v)
Next p
End If
Debug.Print s
Debug.Print Evaluate(s)
Range("Sheet2!" & cell.Address).Formula = s
Next cell
End Sub

 
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
Combine logical formulas "if", "and", "or" pscu Excel Discussion (Misc queries) 5 November 2nd 06 07:43 PM
Combining formulas, "and" & "or" to verify content of multiple cel Shu of AZ Excel Discussion (Misc queries) 15 October 15th 06 11:22 PM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
Why doesn't Excel "word wrap" always expand the cell fully? prettyb Excel Discussion (Misc queries) 1 February 10th 06 03:00 PM
Make linked data "auto-expand" - (?) greenearth Excel Discussion (Misc queries) 5 February 1st 06 12:49 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"