Vba add absolute reference formula in Excel

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

Description:

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 do I restrict user entry in ActiveX Text Box to just numeric values?

2) One of my formulas has returned an error - how can I trace the error to fix it?

3) How can I protect / unprotect WorkSheet using VBA?

4) Here some explanations about XPATH. XPath is a syntax for defining parts of an XML document

5) I have a macro that takes a lot of time for execution - how can I keep the user informed that the macro is running?

6) How can I avoid updates to cell values during macro execution?

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

8) How can I set non-contiguous print area using VBA?

9) How to hide and unhide rows and columns in excel VBA

10) String split in vba in Excel

 

Here the previous and next chapter