+ Reply to Thread
Results 1 to 5 of 5

passing variables to subroutine from userform

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    passing variables to subroutine from userform

    Hi, I'm relatively new to VBA excel programming and have gotten stuck on this problem. I have a sub procedure that is intended to load a list of values into a combobox; I wish to call this from a userform. The call from the user form needs to nominate/pass these variables so the called subroutine can identify the range for the values. The called subroutine is located in a separate module called "mod_ListboxTools".
    Although I've spent some time looking (and experimenting) for what may be at issue my lack of VBA programming concepts is most probably bring me unstuck.
    Any assistance appreciated.

    Calling sub() located in a Userform
    Please Login or Register  to view this content.
    Called subroutine that is located in a module called "mod_ListboxTools"

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: passing variables to subroutine from userform

    What's the problem?

    The code looks fine to me, the only thing I would suggest is to not use the combobox's enter event to populate it.

    Actually just notice something else, you don't need to pass the userform to the sub - passing the combobox on it's own will work.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: passing variables to subroutine from userform

    Hi Norie,
    Thanks for getting back, When stepping through the calling routine it hits the call statement at this line in the code and comes up with an error 13 - as below.

    'call subroutine to load variables
    mod_ListboxTools.ComboLoadList shtName, rngName, cboName, ufrmName

    7-06-2013 3-20-11 PM.jpg

    I've altered the called routine first line but still have the problem as described.
    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: passing variables to subroutine from userform

    I think this is the problem, and it's the part I suggested isn't needed.
    Please Login or Register  to view this content.
    If you did want to pass the userform you could pass it as an Object as you have the combobox.

  5. #5
    Registered User
    Join Date
    05-17-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: passing variables to subroutine from userform

    Hi Norie,
    Mea Culpa!
    (crap! - spent a long time trouble shooting a problem that was the code but not the code)

    I had the same called routine in the userform code area - effectively repeating the code in two places. During trouble shooting I copied this into the same area to compare the code/s. It all runs now and looks like the following. Thanks for your assistance.

    Please Login or Register  to view this content.
    called sub() as below

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1