PDA

View Full Version : Link UserForm with worksheet data



Eduard
02-19-2013, 10:47 AM
Hi,

I need some help with UserForm codes.

I would like the data in UesrForm to be populated from a table in my worksheet and every time I change the UserForm values the changes to be shown in my table. Attached is my example and some codes I manage to make so far.

Thanks for any advice.

Eduard

IRish3538
02-20-2013, 11:54 AM
I didn't open your file (at work), but I think what you want should be pretty easy. you need two subs.. one to "load" the data when you open the userform, and another one to "save" the data when you close it out.

Load:

'Perform this upon "activating" the userform (just double click the userform in design mode to get to this sub
Private Sub UserForm_Activate

'Each textbox/combobox = wherever you're going to have this table
textbox1 = Sheet1.Range("a1")

End Sub


Then to save the data, make a command button at the bottom that says "Submit" or whatever.

'Saves all Userform info and Hides
Private Sub commandbutton1_Click()
'The exact opposite of the one above
sheet1.range("a1") = textbox1
'Or if you want to format the submission
sheet1.range("a1") = format(textbox1,"#,##0")
'Hide Userform
Me.Hide
End Sub