Not sure why you WANT to use VBA... but you can make the code something like this:
------------------------------------------------------------------------
Private Sub CommandButton1_Click()
Dim oSheets As Worksheet
Set oSheets = Worksheets("Sheet1")
oSheets.Range("C2:C5").Value = "=IF(AND(A2="""",B2=""""),"""",A2-B2)" 'Whatever range you want to set.
oSheets.Cells.Locked = False
oSheets.Range("C:C").Locked = True
oSheets.Protect
End Sub
------------------------------------------------------------------------
The above sample does it when a button is clicked.
Also the formula above would be:
=IF(AND(A2="",B2=""),"",A2-B2)
instead of just =A2-B2 since you want "" when there is no values in A or B.
|