• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Insert Excel Formula via VBA code

Hi fellas,

I am working on a vba project and within it I want to insert a standard formula into a range. I have written but somewhere it is not working please help.

Code:
'call resolution time line update
Windows("ABG_2Hrs_Report_Automation_Tool_ver2.0.xlsm").Activate

Range("t2") = "=if(s2*24<2,""<2 Hrs"",if(AND(s2*24>2,s2*24<4),""2-4 Hrs"",if(AND(s2*24>4,s2*24<8),""4-8 Hrs"",if(AND(s2*24>8,s2*24<24),""8-24 Hrs"","">24 Hrs"")))))"
    Range("S1").Select
    Selection.End(xlDown).Select
    Range("K" & n).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.FillDown
    Selection.End(xlUp).Select

You can refer to my code above. It is stopping at the 2nd line (Range("t2")........)
 
Can you try the below..and check if it works fine..

Range("t2").FormulaR1C1 = "=IF(RC[-1]*24<2,""<2 Hrs"",IF(AND(RC[-1]*24>2,RC[-1]*24<4),""2-4 Hrs"",IF(AND(RC[-1]*24>4,RC[-1]*24<8),""4-8 Hrs"",IF(AND(RC[-1]*24>8,RC[-1]*24<24),""8-24 Hrs"","">24 Hrs""))))"
 
Hi,
Change to below code
Range("t2") = "=if(s2*24<2,""<2 Hrs"",if(AND(s2*24>2,s2*24<4),""2
Range("t2").formula = "=if(s2*24<2,""<2 Hrs"",if(AND(s2*24>2,s2*24<4),""2
 
Can you try the below..and check if it works fine..

Range("t2").FormulaR1C1 = "=IF(RC[-1]*24<2,""<2 Hrs"",IF(AND(RC[-1]*24>2,RC[-1]*24<4),""2-4 Hrs"",IF(AND(RC[-1]*24>4,RC[-1]*24<8),""4-8 Hrs"",IF(AND(RC[-1]*24>8,RC[-1]*24<24),""8-24 Hrs"","">24 Hrs""))))"
Hey its working u r champion :)

but it is not dragging down :( .....I am trying to figure it out, if u saw any flaw in my code plz do suggest.
 
Back
Top