Excel/Copy Formula


Good day Bob,
I'm trying to only the Formula of a range but it copies also the Value.
The tricky part is that in the range to be copied, some cells contains FORMULA and some don't.

Here is a test file that I have used to test the code
Sub TestCopyOnlyFormula()
   Application.EnableEvents = False
   Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
   Application.EnableEvents = True
End Sub

I'm I doing something wrong?
Is there an alternative to copy the Formula only?

Thank you.

No - the formula is just evaluating. For example, if cell A1 has 25 in it and cell A2 has 28 in it, and cell B1 has =A1 in it, if you copy B1 and paste only the formula to B2, you'll still see 28 because the formula has =A2, and that evaluates to 28. If you turn calculations off you'll see the 25 instead of 28, but the formula still evaulates to some value.

Also, your code could be shortened to this (no need to select):
Sub TestCopyOnlyFormula()
   Application.EnableEvents = False
   Range("D500:R550").PasteSpecial Paste:=xlPasteFormulas
   Application.EnableEvents = True
End Sub

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Bob Umlas


I`m a Microsoft Excel MVP (Most Valuable Professional) and have been since the inception of the program in 1995. I can answer every kind of Excel question except: API, Importing/exporting to other programs (powerpoint, word,...) Also check out my in-person training link at http://www.thumbtack.com/ny/new-york/excel-training/


Worked with MS Excel since version 0.99 (on the Mac!). Was contributing editor to Excellence Magazine, having written >300 articles. John Walkenbach said of me "I finally met someone who knows as much about Excel as I do."

Excellence, The Expert, Microsoft

BA in math, Hofstra University, 1965

Awards and Honors
Led sessions for the Convergence 2004-2006 seminar on Excel tips & tricks

©2017 About.com. All rights reserved.