



Where it's failing is there are three rows of your old code which shouldn't be there. The Initialize event in the workbook you attached is very close. For example, loading a userform as a variable and controlling it via code. In this example it doesn't make much of a difference, but if you try using userforms a bit more, it's good to know. When you call the Show method, the form loads, which runs the Initialize event. Here are two examples which do exactly the same thing: Load edit_frm This code runs every time the form Load function is called, which is done by default if you Show it. One of those being when the form is opened/loaded and it's called 'UserForm_Initialize'. I like the public property method because it's more flexible, as you can re-use the code in other Thörnlund You're very close! Userforms have events. Private Sub UserForm_Quer圜lose(Cancel As Integer, CloseMode As Integer)Īs another method, opposed to the public property example I showed above, you could have a wrapper function for calling your userform and just handle it all in the initialize event. Since the properties are public, I would destroy them when closing the userform as well, with something like this. ' Add other lines for your userform controls. Me.cbox_bolag.Value = EditTable.DataBodyRange(EditRow.Index, EditTable.ListColumns(2).Index).Value In your userform, you would need an initialize event to see if that property has been set or not, which you could do with something like this. MsgBox "Could not find the selected row.", vbExclamation + vbOKOnly Set EditRow = EditTable.ListRows(ActiveCell.Row - (1, 1).Row + 1) MsgBox "Please select a row in the Table." If Intersect(ActiveCell, EditTable.DataBodyRange) Is Nothing Then Set EditTable = Worksheets("Beställningsunderlag").ListObjects("Tabell1") Public Property Get EditTable() As ListObject The routine 'edit_button_Klicka' would be transformed into: Then you can manipulate the object when/however you want. Thörnlund I would think about utilizing a property for the range of the Table you're wanting to pass to the userform.
