Add Toggle Button with VBA

A toggle button can be a useful tool in conjunction with a command button.  The idea is when you click on the command button the button caption will change or 'toggle' to match the opposite of the action just performed.  This will mean the next action which is listed on the command button will be the action you are performing.  An example is to have Yes appear when you click on the button and once Clicked No appears on the button.

Column B is sorted and the button says Sort C.  So the next time the button is clicked the caption will change to Sort B and Column C will be sorted.  The following is the code to produce a toggle effect on a Command Button.  The Command Button in the below example is called cmdB1.

Option Explicit

Private Sub cmdB1_Click() 'Excel VBA procedure to sort based on a condition.
If cmdB1.Caption="Sort B" Then
Range("a12", Range("C65536").End(xlUp)).Sort [B12], 1
cmdB1.Caption="Sort C"
Else Range("a12", Range("C65536").End(xlUp)).Sort [C12], 1
cmdB1.Caption="Sort B"
End If
End Sub

The following Excel file outlines the procedure VBA procedure above.