• 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.

how to apply specific formula in selected range using vba

Amit Modi

Member
hi ninja's

please explain me that how can I apply one specific formula in selected range I sheet using VBA.i am new to vba please provide sample code please.

example:: If [a1]+[b1]>5 then write text "ok" in range("c1:c20").

please help me.

please also provide if I want corresponding results I.e.( a1+b1)>5 then c1=ok
if (a2+b2)>5 then c2=ok
etc..
 
Last edited:
hi ninja's

please explain me that how can I apply one specific formula in selected range I sheet using VBA.i am new to vba please provide sample code please.

example:: If [a1]+[b1]>5 then write text "ok" in range("c1:c20").

please help me.

please also provide if I want corresponding results I.e.( a1+b1)>5 then c1=ok
if (a2+b2)>5 then c2=ok
etc..
Hi,

One way

Code:
Sub Values()
Dim c As Range
For Each c In Range("A1:A20")
If WorksheetFunction.Sum(c.Resize(, 2)) > 5 Then
  c.Offset(, 2) = "Ok"
End If
Next
End Sub
 
mike is there any simple code?? I just want to understand as i am beginner.otherwise its great
Hi,

This one actually puts the formula on the worksheet.

Code:
Sub somesub()
With Range("C1")
  .Formula = "=if(a1+b1>5,""Ok"","""")"
  .Resize(20).FillDown
End With
 
Back
Top