Hello,

Userform1 has 3 command buttons and 3 text boxes. A mouse click on a text box followed by a command button click a value of 1, 2, or 3, respectively, is entered in the text box. This is the code:

Private Sub cmb1_Click() 
    KeyPad ("1")
  
End Sub

Private Sub cmb2_Click() 
    KeyPad ("2")
End Sub

Private Sub cmb3_Click() 
    KeyPad ("3")

End Sub
Private Sub KeyPad(sKey)
        lastActiveTextbox.Text = lastActiveTextbox.Text & sKey
End Sub
The condition and action I want to add to the code is:
1. Only one command button value is permissible in a text box
2. If a text box contains a value, pressing the command button will clear the text box and
2a. enter the command button value.

Any thoughts on how I can write this in to my existing code?

Thank you in advance.
Gal403