vba add absolute reference formula in Excel

Q170. In Excel, how do I enter a formula in a cell using VBA?

For example, I want to enter the formula "=Iferror(B2/C2,"")" in Cell D2 using VBA

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub AddFormula()
  3. ActiveSheet.Range("D2").Formula = "=IFERROR(B2/C2,"""")"
  4. End Sub


a) Line 3 - The exact formula text including "=" should appear within double quotes. Notice the use of specifying quotes twice within brackets so that they appear once in formula when written to cell.


You can find similar Excel Questions and Answer hereunder

1) How can I get users to select a file for processing using my macro?

2) How can I get row count of filtered data?

3) How can I set FreezePanes in a certain range using VBA?

4) How can I turn off Alerts using VBA?

5) How can I copy and rename a WorkSheet using VBA?

6) Import txt file in Excel

7) How can I add a Footer to my printout with automatic page numbering?

8) How to concatenate strings in vba in Excel

9) Can I add a small chart to Table data to make it visually appealing and easy to interpret?

10) Line break in vba message box in Excel

11) How can I get input from user through a prompt and assign user's input to a cell?

12) Vba delete entire row if contains certain text in Excel

13) How can I filter and copy only filtered data using VBA?

14) How can worksheet functions be accessed in VBA?

15) How can I activate a routine when there is a change in value of a cell?