Link to home
Avatar of Tocogroup
TocogroupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Is it possible to pass a parameter from a VBA sub to a User Form ?


I have an Excel VBA application which displays a User Form when I click in the first column of a sheet (it displays the field values of the row clicked upon, in the User Form).

The User Form allows me to update the fields and then click on an "Update" button which will update the original sheet row with the new values.

However, I'm getting compilation errors because I'm not sure how to work out which row it should be updating. If I could pass the row number as a parameter from the sheet to the User Form then that would do the trick. But I can't get that to work either.

Any ideas
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Put something like

Pubikc  TheRow As Long

At the top if some module. You can then modify it and read it from anywhere.
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
How is your UserForm displayed? You can do this by setting your userform to a variable itself and having a control (set to hidden) get this value. But I'm not sure you need to go that far really. Is it the active cell? If so, just use that range object. I'd do either of those before using a Public variable, but that works as well.

Zack Barresse
Avatar of Tocogroup


Hah, wondering what you were trying to say.
Many thanks for that. Works a treat.