Paste data into worksheet then back into UserForm

Kyle M

Board Regular
Joined
Apr 13, 2010
Messages
65
Code:
[FONT=Times New Roman][SIZE=3]Private Sub CommandButton1_Click()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]With Sheets("Sheet4")[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A1").Value = TextBox1.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A7").Value = TextBox2.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A15").Value = TextBox3.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A21").Value = TextBox4.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A36").Value = TextBox5.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A40").Value = TextBox6.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3].Range("A41").Value = TextBox7.Text[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]End With[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Unload Me[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]UserForm4.Show[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]

The code above pastes data from a UserForm to Sheet4 when I click the command button. In the last line of this block of code, after I call UserForm4 again, I would like to have the data I pasted into Sheet4 to get pasted back into the TextBoxes in UserForm4. Is this possible? If so can you show me how?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Just reverse this part in the form's Initialize event:

Code:
.Range("A1").Value = TextBox1.Text
.Range("A7").Value = TextBox2.Text
.Range("A15").Value = TextBox3.Text
.Range("A21").Value = TextBox4.Text
.Range("A36").Value = TextBox5.Text
.Range("A40").Value = TextBox6.Text
.Range("A41").Value = TextBox7.Text

HTH
 
Upvote 0
The data should be in the textboxes until you unload it?

Or is UserForm4 a different userform?

If it is then just use it's Initialize event but 'reverse' the code
Code:
Private Sub UserForm_Intialize()
 
 With Sheets("Sheet4")
   TextBox1.Text = .Range("A1").Value
   TextBox2.Text = .Range("A7").Value
   TextBox3.Text = .Range("A15").Valu
   TextBox4.Text = .Range("A21").Value
   TextBox5.Text = .Range("A36").Value
   TextBox6.Text = .Range("A40").Value
   TextBox7.Text = .Range("A41").Value
 End With

End Sub
 
Upvote 0
Thank you Smitty. Thank you Norie. Your feedback is helpful. Perhaps my error, when I try the code I got an error message that reads 'Invalid or unqualified reference' do you know why that might be?
 
Upvote 0
Can you post the exact code you tried?

By the way, I was trying to say you might not need to repopulate the textboxes if it's only the one form.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top