View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Problem using DirectDependents

Option Explicit

Sub test()
ResolveFormula Range("D6")
End Sub

Sub ResolveFormula1(rngCell As Range)
Dim sCell As String
Dim rngPrec As Range
Dim index As Long
sCell = rngCell.Formula
index = 64
For Each rngPrec In rngCell.DirectPrecedents
index = index + 1
sCell = Replace(sCell, rngPrec.Address(False, False), Chr(index))


Next
rngcell.offaset(,1).Value= "'" & sCell
End Sub


"Kevin Beckham" wrote:

With a leading space so it is not a true formula
" =A * B"

With error-trapping, it can be called from a sub-routine, but not from a
worksheet

"Kevin Beckham" wrote:

I didn't express myself clearly

I would like it to return the string "=A * B"
At present, it returns "=B1 * B2"


"Patrick Molloy" wrote:

you can't put = A * B into a cell, its "illegal"




"Kevin Beckham" wrote:

I can't get the following function to return the direct dependents

Function ResolveFormula(ByRef rngCell As Range, iColLabels As Integer) As
String
Dim sCell As String
Dim rngPrec As Range

sCell = rngCell.Formula

For Each rngPrec In rngCell.DirectPrecedents
With rngPrec
sCell = Replace(sCell, rngPrec.Address(False, False, xlA1), _
.Offset(0, iColLabels - .Column + 1).Value)
End With
Next rngPrec

ResolveFormula = sCell
End Function

For the worksheet
A 1
B 2
=B1 * B2 =ResolveFormula(B3, 1)

to give =A * B

TIA
Kevin Beckham