+ Reply to Thread
Results 1 to 9 of 9

Populating a Multi column Combobox in a userform

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Populating a Multi column Combobox in a userform

    Hi,

    I am working on a project relating to employee management. I have created a UserForm which enables the user to select the employee for modification, reports, etc.

    This userform has a combobox which I want to populate with an two dimensional array that has 4 columns and as many rows as there are employees. The employee data is stored in a worksheet called "PERS". I want the combobox to display the 4 columns as Employee ID (Column C), Surname (Column F), First name (Column G) and Middle Name (Column H). The data starts in row 3. Headers occupy rows 1 and 2.

    I am having a problem with loading the combobox with the data. The code that I have currently is given below

    Please Login or Register  to view this content.
    I keep getting error "Subscript out of range" on the line

    Please Login or Register  to view this content.
    Can some one help point out where I have gone wrong and give the solution to populate the combobox. I have been searching the web for likely solutions but none have worked so far.

    Please excuse if there is an elementary error - I am still low on the learning curve

    Thanks in advance for your patience

    Anand
    Last edited by anandvh; 12-14-2012 at 04:12 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Both of the dimensions of MyArray begin at 1 not 0.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Re: Populating a Multi column Combobox in a userform

    @Norie - I substituted iCol and iRow in my code above with 1. Now i get Run Time Error 1004 : Method 'Range of Objects'_Global' failed

    Regards, Anand

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Which line of code do you get the new error on?

  5. #5
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Re: Populating a Multi column Combobox in a userform

    The error comes on the line

    Please Login or Register  to view this content.

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

    Re: Populating a Multi column Combobox in a userform

    What's the value of iSou when you get the error?

    Also, where do you give a value to iLst?

  7. #7
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Re: Populating a Multi column Combobox in a userform

    The value of iSou = 3, the first row of data, which is correct.

    iLst is not used anywhere and should have been deleted. iLst was declared to store the last populated row in the worksheet. Since tRow variable already stores this value, iLst is not used.

    To give you a better idea of what I am trying to do, I have attached a sample workbook. Hope this will be of help

    Regards,

    Anand
    Attached Files Attached Files

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

    Re: Populating a Multi column Combobox in a userform

    Range should be Cells.

    Actually that's not right.

    What are you trying to refer to here?
    Please Login or Register  to view this content.

    Anyway, try this.
    Please Login or Register  to view this content.
    Last edited by Norie; 12-14-2012 at 03:30 PM.

  9. #9
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Re: Populating a Multi column Combobox in a userform

    Your codes works like a dream. I was able to get the mistakes I was making. This is the first time I am attempting to use a two dimensional array. My learning curve just went up a couple of notches.

    Thanks Norie for your interest and assistance.

    Regards,

    Anand

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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