copy cell formula

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,604
Office Version
  1. 365
Platform
  1. Windows
Hi

Cell B41 contains the formula
Code:
=$B384
anybody know how I can copy this formula value preceeded by a " ' "
and paste into cell AL1

so with above example AL1 will now be populated with following text
'=$B384

note!!!

Cell B41 will hold different values and will NOT always be =$B384

thanks in advance
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi

Whatever the formula in cell B41 is I just want to copy it preceeded with a " ' " and paste it into another cell

as I said the cell formula in B41 could be anything

hope you can help
 
Upvote 0
this is tricky…..it uses an old artifact of Excel Macro.

Highlight cell AL1 then CTRL+F3 to Define a Named Range
Name the range FindCell
In the 'refers to' type in =get.cell(6,B41), click ADD, Click OK
then in Cell AL1, enter =FindCell
This returns the formula value in cell B41 as text so you don't need to preceed it with a ' mark.
 
Upvote 0
I use a UDF for this, primarly for posting examples in the forum:
Code:
Function GetFormula(r As Range, _
                    Optional ByVal sText As String = "", _
                    Optional ByRef bA1 As Boolean = True) As String
    ' shg 2007
 
    Dim sL          As String   ' left brace for array formula
    Dim sR          As String   ' right brace for array formula
    Dim sAdrs       As String
 
    Select Case FormulaType(r)
        Case 0              ' no formula
            sAdrs = r.Address(False, False)
            If Len(sText) Then sText = " " & sText
            sText = sText & ": "
            GetFormula = r.Address(False, False) & sText & "Input"
            Exit Function
        Case 1
            sAdrs = r.Address(False, False)
        Case 2, 3
            sL = "{"
            sR = "}"
            sAdrs = r.Address(False, False)
    End Select
 
    ' pad text with a leading space and trailing colon
    If Len(sText) Then sText = " " & sText
    sText = sText & ": "
    GetFormula = sAdrs & sText & sL & IIf(bA1, r(1).Formula, r(1).FormulaR1C1) & sR
End Function
 
Function FormulaType(cell As Range) As Long
    ' shg 2007
 
    ' Returns the type of formula in cell
    '   multi-cell array formula .... 3
    '   single-cell array formula ... 2
    '   regular formula ............. 1
    '   no formula .................. 0
 
    With cell
        If .HasArray Then
            FormulaType = IIf(.CurrentArray.Cells.Count > 1, 3, 2)
        Else
            FormulaType = IIf(.HasFormula, 1, 0)
        End If
    End With
End Function

So for your example,

=GetFormula(B41) returns B41: =$B384
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,223
Members
452,896
Latest member
IGT

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