question

MichaelCavaggioni-8875 avatar image
0 Votes"
MichaelCavaggioni-8875 asked MichaelCavaggioni-8875 commented

What is a simple Code for Userform?

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

office-vba-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MichaelCavaggioni-8875
Based on your description, your issue is more related to code, I will modify the tag. Thanks for your understanding.

1 Vote 1 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered MichaelCavaggioni-8875 commented

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.


· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Viorel-1 - thank you so much. unfortunately its not doing anything. nothing enters into spreadsheet. no error messages either

here is a screens hoot of my sheet with command box


82735-image.png


0 Votes 0 ·
image.png (40.1 KiB)
Viorel-1 avatar image Viorel-1 MichaelCavaggioni-8875 ·

Maybe the code is not good. Show some details. Which code is executed when you press "ADD"?

0 Votes 0 ·

thank you for your reply @Viorel-1
nothing executes when i run the macro

82786-image.png


0 Votes 0 ·
image.png (10.3 KiB)
Show more comments