Check to see if a formula is correct

O

oldjay

I want to do something like this
Sub Macro1()

If Range("A1") =(=B1 + B2) Then ' This is a formula
Exit Sub
Else
Range("C1").Select 'Has correct formula
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlFormulas
End If

End Sub
How do I do this?
 
R

Roger Govier

Hi

Try
Sub Macro1()

If Range("A1").HasFormula Then
Exit Sub
Else
Range("C1").Copy
Range("A1").PasteSpecial Paste:=xlFormulas
Application.CutCopyMode = False
End If

End Sub

Regards
Roger Govier
 
J

Jacob Skaria

Try

If Range("A1").Formula <> "=B1+B2" Then
Range("A1").Formula = Range("C1").Formula
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top