Total Pageviews

Wednesday 23 July 2014

Implementing cell formula to VBA Code

Implementing cell formula to VBA Code

Many people struggle or make mistakes while implementing formula to VBA code. Here is the best way to put the formula to VBA code

Let’s say we have a formula in cell B2 as below

=IF(F2="","",DATEDIF(F2,TODAY(),"d"))

STEP: 1
Open your vb screen  > insert the module and insert below code

Sub insert_formula()
Range (“B2”).Formula=paste_formula_here
End sub

STEP: 2
Before you paste your formula within the above quotation you should copy the cell formula to a notepad
after pasting , use CTRL+H key within notepad
Find what: “
Replace with: “”

After replacing  formula will be,

=IF(F2="""","""",DATEDIF(F2,TODAY(),""d""))

Copy the above replaced version and paste it in paste_formula_here  in VBA code

Sub insert_formula()
Range(“B2”).Formula==IF(F2="""","""",DATEDIF(F2,TODAY(),""d""))
End sub



No comments:

Post a Comment