ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check to see if a formula is correct (https://www.excelbanter.com/excel-programming/440071-check-see-if-formula-correct.html)

Oldjay

Check to see if a formula is correct
 
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?

Roger Govier[_8_]

Check to see if a formula is correct
 
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

oldjay wrote:
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?


Jacob Skaria

Check to see if a formula is correct
 
Try

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

--
Jacob


"oldjay" wrote:

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?


Oldjay

Check to see if a formula is correct
 
Thanks

"Jacob Skaria" wrote:

Try

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

--
Jacob


"oldjay" wrote:

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?



All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com