Sub Add_Value()
If Range("A1").Value ="1" Then
Range("A1").Value = "0"
Else: Range("A1").Value = "1"
End If
End Sub
You can simplify while eliminating the slow IIf function at the same time...Try:-
Code:Private Sub CommandButton1_Click() With Range("A1") .Value = IIf(.Value = 1, 0, 1) End With End Sub
Private Sub CommandButton1_Click()
With Range("A1")
.Value = 1 - .Value
End With
End Sub
Private Sub CommandButton1_Click()
Range("A1").Value = 1 - Range("A1").Value
End Sub
You can simplify while eliminating the slow IIf function at the same time...
Code:Private Sub CommandButton1_Click() With Range("A1") .Value = 1 - .Value End With End Sub
Although I would probably eliminate the With..End With block (not sure anything is gained by using it when there is only 2 references to its object)...
Code:Private Sub CommandButton1_Click() Range("A1").Value = 1 - Range("A1").Value End Sub