ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting the formula of a cell as text (https://www.excelbanter.com/excel-programming/274805-getting-formula-cell-text.html)

Beto[_2_]

Getting the formula of a cell as text
 
Hi,
I want to create a macro that puts the cursor over a cell which is
retrieved from the cell it's standing on.
Wow, I notice english is not my first language, because even I can't
really understand what I just wrote :)

An example would be better.

Let's say I'm standing on a cell with the formula "=A25".
Now when I'm standing on this cell I want to run a macro that moves
the cursor over the referenced cell (A25).

Now I can go to a cell if I have the position of the cell as text in
the current cell as:

Range(Activecell.Value).Select

How can I achieve this to replace Activecell.value with the text
gotten from the formula?

TIA
Regards,
--
Beto

Michael Tomasura

Getting the formula of a cell as text
 
Try something like this

x = Mid(Selection.Formula, 2, Len(Selection.Formula))
Range(x).Select



--

"Beto" wrote in message
om...
Hi,
I want to create a macro that puts the cursor over a cell which is
retrieved from the cell it's standing on.
Wow, I notice english is not my first language, because even I can't
really understand what I just wrote :)

An example would be better.

Let's say I'm standing on a cell with the formula "=A25".
Now when I'm standing on this cell I want to run a macro that moves
the cursor over the referenced cell (A25).

Now I can go to a cell if I have the position of the cell as text in
the current cell as:

Range(Activecell.Value).Select

How can I achieve this to replace Activecell.value with the text
gotten from the formula?

TIA
Regards,
--
Beto




Tom Ogilvy

Getting the formula of a cell as text
 
Actually It should be directprecedents - precendents includes more than
directprecedents.

Sub MoveTo()
Dim rng As Range
If ActiveCell.HasFormula Then
On Error Resume Next
Set rng = ActiveCell.DirectPrecedents
On Error GoTo 0
If Not rng Is Nothing Then
rng.Areas(1).Select
End If
End If
End Sub

--
Regards,
Tom Ogilvy

Tom Ogilvy wrote in message
...
Assuming you are not trying to move to another sheet:

Sub MoveTo()
Dim rng As Range
If ActiveCell.HasFormula Then
On Error Resume Next
Set rng = ActiveCell.Precedents
On Error GoTo 0
If Not rng Is Nothing Then
rng.Areas(1).Select
End If
End If
End Sub


--
Regards,
Tom Ogilvy



Beto wrote in message
om...
Hi,
I want to create a macro that puts the cursor over a cell which is
retrieved from the cell it's standing on.
Wow, I notice english is not my first language, because even I can't
really understand what I just wrote :)

An example would be better.

Let's say I'm standing on a cell with the formula "=A25".
Now when I'm standing on this cell I want to run a macro that moves
the cursor over the referenced cell (A25).

Now I can go to a cell if I have the position of the cell as text in
the current cell as:

Range(Activecell.Value).Select

How can I achieve this to replace Activecell.value with the text
gotten from the formula?

TIA
Regards,
--
Beto






Peter Atherton

Getting the formula of a cell as text
 
Hello Beto

A similar solution to Tom's is:

Sub MyIndirect()
Dim Cell As Range
Dim s As String
If ActiveCell.HasFormula = False Then
MsgBox "There is no formula in this cell", , "Error_
Alert"
Exit Sub
Else: s = "" & ActiveCell.Formula & ""
Range(s).Select
End If
End Sub


Beto[_2_]

Getting the formula of a cell as text
 
Thanks to all who answered. I'll try the solutions soon!

Regards,
--
Beto

"Peter Atherton" wrote in message ...
Hello Beto

A similar solution to Tom's is:

Sub MyIndirect()
Dim Cell As Range
Dim s As String
If ActiveCell.HasFormula = False Then
MsgBox "There is no formula in this cell", , "Error_
Alert"
Exit Sub
Else: s = "" & ActiveCell.Formula & ""
Range(s).Select
End If
End Sub



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com