+ Reply to Thread
Results 1 to 10 of 10

Fill Combo and List Box with items from A1:A5

  1. #1
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Fill Combo and List Box with items from A1:A5

    I am working on an assignment and cannot figure out what I've done wrong. I am trying to get the states listed in A1:A5 to list in a listbox when the command button is clicked. I am getting an error: 1ststates not defined.
    Here is what my excel page looks like:
    ExcelStates.jpg
    And my code:
    Please Login or Register  to view this content.
    Any help is much appreciated.
    Last edited by LadyB; 04-12-2013 at 03:39 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Fill Combo and List Box with items from A1:A5

    Please Login or Register  to view this content.
    Change the "A" in both lines to a 1
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Fill Combo and List Box with items from A1:A5

    Quote Originally Posted by AndyLitch View Post
    Please Login or Register  to view this content.
    Change the "A" in both lines to a 1
    That doesn't change the error of "Variable not defined" that I keep getting.

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Fill Combo and List Box with items from A1:A5

    at the top of the code put Dim introwindex as integer

  5. #5
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Fill Combo and List Box with items from A1:A5

    Quote Originally Posted by AndyLitch View Post
    at the top of the code put Dim introwindex as integer
    I still get the same error. It highlights the 1stStates. I'm not sure how to define it.

  6. #6
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Fill Combo and List Box with items from A1:A5

    Can you upload the workbook? It'll save time..

  7. #7
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Fill Combo and List Box with items from A1:A5

    Quote Originally Posted by LadyB View Post
    I still get the same error. It highlights the 1stStates. I'm not sure how to define it.
    I listed at the top

    Dim introwindex As Integer
    Dim lstStates As ListBox
    Dim cboStates As ComboBox


    Now when I click the fill list I get a runtime error and it highlights "lstStates.AddItem Cells(intRowIndex + 1, "A")" in yellow.

  8. #8
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Fill Combo and List Box with items from A1:A5

    Quote Originally Posted by AndyLitch View Post
    Can you upload the workbook? It'll save time..
    If i knew how, I have zipped it, but see no upload file option.

  9. #9
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Fill Combo and List Box with items from A1:A5

    lstStates.AddItem(Cells(intRowIndex + 1, 1).value)

  10. #10
    Registered User
    Join Date
    03-11-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Fill Combo and List Box with items from A1:A5

    Quote Originally Posted by AndyLitch View Post
    lstStates.AddItem(Cells(intRowIndex + 1, 1).value)
    I figured it out, I hadn't named my list box or Combo box correctly, but thanks for helping.

+ 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