0

I want to copy paste the cell values what we see post pressing F9 in a cell into word. Is there any short and quick way to do this?

For example - if I have a formula: =AVERAGE(E12/H12,E11/H11,E10/H10)

if I press F9 6 times: =AVERAGE(18.8064516129032/18.0469173899242,15.5862068965517/13.1790029444614,16.6470588235294/16.6666666666667)

I want to paste the above to Word document instead of the formulae with cell references. I want to do these for a large number of cells. Doing F9 and then pasting each cell is time consuming.

Is there any shortcut/macros or any quick way to do the above without pressing F9 six times? My formulae contains absolute references, relative references and array formulae as well in some instances. So, looking for something that would work for a range of cells where I would like to replicate the F9 feature.

2 Answers 2

1

You can use this macro code.

Sub FormulaPrec()
    Dim fText As String, prec
    fText = Selection.Formula
    For Each prec In Selection.DirectPrecedents
       fText = Replace(fText, prec.Address(0, 0), Str(prec.Value))
    Next prec
    MsgBox fText
    ' copy to clipboard
    CreateObject("htmlfile").parentWindow.clipboardData.setData "text", fText
End Sub

If different types of addresses (with and without $) are used in a formula you should convert all addresses to the same type before changing them to values.

Sub FormulaPrec1()
    Dim fText As String, prec
    fText = Selection.Formula
    fText = Application.ConvertFormula(fText, xlA1, xlA1, xlAbsolute)
    For Each prec In Selection.DirectPrecedents
       fText = Replace(fText, prec.Address, Str(prec.Value))
    Next prec
    MsgBox fText
    ' copy to clipboard
    CreateObject("htmlfile").parentWindow.clipboardData.setData "text", fText
End Sub

Before you use it, you need to select the cell that contains the formula. Using the Str function in this code is unnecessary if you use a period as a decimal separator in your Excel. In the last line, the formula is copied to the clipboard, from where it can be pasted with Ctrl+V to the desired location, e.g. in a Word document. Precedent_Values

5
  • Thank you so much for helping me. You saved a lot of time for me. It works. I am going to improvise this and put to use. : ) Commented Apr 4 at 0:42
  • Is there any way to apply this for a range of cells? It works for 1 single cell for me. Also fails when fixed references are encountered eg $G$12, and also not working on arrays eg C12#/F12# Commented Apr 4 at 0:49
  • "Apply this for a range of cells". What do you mean by that? A range of cells with different formulas, or reference to a range in a formula? When it comes to several formulas, you can add a loop, but what form would the result be in? Range references in formulas – this is rather difficult to achieve. For the same reasons, this will not work with the # operator.
    – MGonet
    Commented Apr 4 at 11:25
  • 1
    Second question, the form of the address is given by the arguments of the Address method. If you want the address to be $A$1, use Address(1,1) or Address with no arguments. If there are different types of addresses in the same formula, then the conversion to one type of addressing should be applied. I have updated the reply.
    – MGonet
    Commented Apr 4 at 11:25
  • Thank you @MGonet Commented Apr 8 at 4:22
0

You can use

="AVERAGE("&E12&"/"&H12&","&E11&"/"&H11&","&E10&"/"&H10&")"

Then copy the result of this formula.

enter image description here

2
  • If that resolved your issue, please mark the answer as described in the tour. If it didn't, please leave a comment, so I can follow up.
    – teylyn
    Commented Apr 3 at 2:32
  • Nope, too much effort to do this for different different cells. The issue is formulae are not draggable. I want to create a document where I need to pick certain figures from different cells. I am looking for some quick method that would save a lot of time for me. I am thinking of some macro that can replicate F9 feature and paste as values in destination but unsure how to paste it with formulae as some form of string. So this F9 feature must replicate only where some cell references are found inside a formulae. I am thinking on these lines. Commented Apr 3 at 4:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .