Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem using DirectDependents

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Problem using DirectDependents

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem using DirectDependents

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem using DirectDependents

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Problem using DirectDependents

That's similar to what I ended up with - the function cannot be called from a
worksheet though.

Thanks for your input.


Function ResolveFormula(ByRef rngCell As Range, iColLabels As Integer) As
String
'can only be called by a subroutine
Dim sCell As String
Dim rngPrec As Range
Dim rngPrecs As Range

sCell = rngCell.Formula
On Error Resume Next
Set rngPrecs = rngCell.DirectPrecedents
On Error GoTo 0

If Not rngPrecs Is Nothing Then
For Each rngPrec In rngPrecs
With rngPrec
sCell = Replace(sCell, rngPrec.Address(False, False, xlA1), _
" [" & .Offset(0, iColLabels - .Column).Value & "] ")
End With
Next rngPrec
End If

ResolveFormula = " " & sCell
End Function


"Patrick Molloy" wrote:

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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Problem using DirectDependents

Try the below UDF and feedback

Function ResolveFormula(ByRef rngCell As Range) As String
Dim blnString As Boolean
ResolveFormula = rngCell.Formula

For intTemp = 1 To Len(ResolveFormula)
If Mid(ResolveFormula, intTemp, 1) = Chr(34) Then _
blnString = Not blnString
If IsNumeric(Mid(ResolveFormula, intTemp, 1)) And _
blnString = False Then Mid(ResolveFormula, intTemp, 1) = Chr(116)
Next

ResolveFormula = Replace(ResolveFormula, Chr(116), "")
End Function

If this post helps click Yes
---------------
Jacob Skaria


"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


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
DirectDependents not working properly. [email protected] Excel Programming 1 February 3rd 08 03:39 AM
What's the difference between .Dependents and .DirectDependents? [email protected] Excel Programming 4 February 3rd 08 03:27 AM
Finding when there are no directdependents [email protected] Excel Programming 1 June 19th 06 10:46 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


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