Button with 2 functions VBA

KlausW

Active Member
Joined
Sep 9, 2020
Messages
381
Office Version
  1. 2016
Platform
  1. Windows
Hello, is it possible to make a button that on the first press puts 1 in cell E1 and if I press it once more puts a 0 in cell E1.
I have tried with this VBA code but it doesn't do what I want.
Any help will be appreciated.
Best Regards
Klaus W

VBA Code:
Private Sub CommandButton1_Click()
   
Range("D3").Value = Range("D3") + 1
 
Range("D3").Value = Range("D3") - 1

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Like this?

VBA Code:
Private Sub CommandButton1_Click()
  With Range("E1")
    .Value = 1 - .Value
  End With
End Sub
 
Upvote 0
Solution
Like this?

VBA Code:
Private Sub CommandButton1_Click()
  With Range("E1")
    .Value = 1 - .Value
  End With
End Sub
Hi Peter_SS
Just as it should be, thank you very much.
Good day from here in Denmark
Best regards
Klaus W
 
Upvote 0

Forum statistics

Threads
1,215,109
Messages
6,123,136
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top