ActiveX command Button

FootBallBat

Board Regular
Joined
Jan 26, 2012
Messages
169
Hello I am looking for a code that when the command button is clicked it will change "B1"
Private Sub CommandButton2_Click()
If "B1" = 1 then "B1" = 2
else
If "B1" = 2 then "B1" = 1

I realize this is not a code it's just and example of what I'm looking for.
Thank you
 
Last edited:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:
Code:
Private Sub CommandButton2_Click()
'Modified  4/11/2019  9:07:12 PM  EDT
If Range("B1").Value = 1 Then
    Range("B1").Value = 2
Else
If Range("B1").Value = 2 Then
    Range("B1").Value = 1
End If
End If
End Sub
 
Upvote 0
Or This:
Code:
Private Sub CommandButton2_Click()
'Modified  4/11/2019  9:15:23 PM  EDT
If Range("B1").Value = 1 Then Range("B1").Value = 2: Exit Sub
If Range("B1").Value = 2 Then Range("B1").Value = 1: Exit Sub
End Sub
 
Upvote 0
Or this:
Code:
Private Sub CommandButton2_Click()
'Modified  4/11/2019  9:23:41 PM  EDT
With Range("B1")
    Select Case Range("B1").Value
        Case 1
            .Value = 2
        Case 2
            .Value = 1
    End Select
End With
End Sub
 
Upvote 0
Or like this:
Code:
Private Sub CommandButton2_Click()
'Modified  4/11/2019  9:30:41 PM  EDT
With [B1]
    Select Case [B1]
        Case 1
            .Value = 2
        Case 2
            .Value = 1
    End Select
End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

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