pull the cell ref from a formula

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,

i need a macro that can take the cell ref from a formula, that is "=Control!A9" so i need the macro to pull the "A9" part only

and paste it into D7

please must be a macro not a formula


Thanks

Tony
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Are all the formulas just like that or might there be ones like these and if so what should these results be?

=A5+$B$33+200
=SUM(A34:K$15)
=INDEX(A:A,5)
 
Upvote 0
@Rick Rothstein posted this previously....All credit to Rick
I've modified to suit
VBA Code:
Sub MM1()
    Dim Rng As Range, Frm As String
    Dim WF As WorksheetFunction, Sh As String, Ref As String
'   *** Change sheet and range references to suit ***
    Set Rng = Worksheets("Control").Range("E1")
    Frm = Rng.Formula
    Set WF = WorksheetFunction
    Ref = Right(Frm, Len(Frm) - WF.Find("!", Frm, 1))
    Range("D7").value= Ref
End Sub
 
Upvote 0
Seems like an awful lot of code for something I would have posted.o_O I have no recollection of that code, but my thinking now would be for something a lot more condensed...
VBA Code:
Sub RR1()
  Range("D7").Value = Split(Worksheets("Control").Range("E1").Formula, "!")(1)
End Sub
 
Upvote 0
My sincerest apologies Rick.......@Andrew Poulsom was the writer......?
 
Upvote 0
I'm not seeing anything that suggests the formula is on the 'Control' worksheet. To me the inference is quite the opposite.
So assuming the formula is on the active sheet in cell C7 & the result is to go on the active sheet cell D7 ..

VBA Code:
Sub ExtractRef()
  Range("D7").Value = Split(Range("C7").Formula, "!")(1)
End Sub
 
Upvote 0
Solution
Thank you Peter, Rick and Michael,
This is everything I needed, so a massive thanks for that
Tony
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top