What is a simple Code for Userform?

Michael Cavaggioni 1 Reputation point
2021-03-29T21:07:50.957+00:00

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: Most helpful
  1. Viorel 112.1K Reputation points
    2021-03-30T05:29:16.62+00:00

    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.