What is a simple Code for Userform?

Michael Cavaggioni 1 Reputation point

im adding a userform into my spreadsheet and want to add a click button. very new to code::: what code would i write to simply add text written into the userform into my spreadsheet. thank you all in advance

{count} votes

1 answer

Sort by: Newest
  1. Viorel 89,156 Reputation points

    Go to your userform designer, insert the TextBox and CommandButton (dragging from Toolbox), and then double click the added button to go to Click handler. Then enter a code like this:

    Private Sub CommandButton1_Click()
        Dim ws As Worksheet
        Set ws = ActiveSheet
        ws.Range("A1").Value = TextBox1.Text
    End Sub

    (Adjust the names if your controls are called differently). This example copies the text from textbox to A1 cell of current worksheet.