Search code examples
vbatextbox

I want to add two textboxes together


I have 2 text boxes and a label.

I want to be able to display in a label the concatenated text of the two textboxes. I have used the following code:

Private Sub CommandButton1_Click()

    Label1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)  

End Sub

This doesn't work, however, and I am getting

Compile error: Method or data member not found

Can somebody explain why this is happening and how I can fix it, please?


Solution

  • In a Macro enabled excel file, add the activeX version of command button, text boxes and label.

    After this you can have your desired result with this code:

    Private Sub CommandButton1_Click()
    Label1.Caption = TextBox1.Text & TextBox2.Text
    End Sub
    

    Please check that the macros are saved correctly. This solution works on Excel 2013.