+ Reply to Thread
Results 1 to 9 of 9

Listbox or Combox help

Hybrid View

Biplab1985 Listbox or Combox help 08-15-2016, 05:20 AM
isskint Re: Listbox or Combox help 08-15-2016, 08:39 AM
Biplab1985 Re: Listbox or Combox help 08-15-2016, 11:43 AM
isskint Re: Listbox or Combox help 08-15-2016, 11:55 AM
Biplab1985 Re: Listbox or Combox help 08-15-2016, 12:12 PM
Biplab1985 Re: Listbox or Combox help 08-15-2016, 12:30 PM
Biplab1985 Re: Listbox or Combox help 08-15-2016, 02:36 PM
sanram Re: Listbox or Combox help 08-15-2016, 03:11 PM
Biplab1985 Re: Listbox or Combox help 08-15-2016, 06:55 PM
  1. #1
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Listbox or Combox help

    Looking for a code to populate a list based on selection on another listbox

    e.g, if user selects Month in listbox1, listbox2 should populate with - Jan, Feb, Mar etc
    Last edited by Biplab1985; 08-15-2016 at 08:10 AM.

  2. #2
    Registered User
    Join Date
    06-21-2013
    Location
    Wiltshire, UK
    MS-Off Ver
    365 Version 2210 Build 16.0.15726.20070
    Posts
    72

    Re: Listbox or Combox help

    Run a for next loop to go through each row of data for your second data set checking if the selection of listbox1 matched the relevant column and add the data row by row.

    EG listbox 1 = Month

    data source for listbox 2 =
    Type	Value
    Month	Jan
    Month	Mar
    Month	May
    Month	Sept
    Month	Dec
    Day	Mon
    Day	Tue
    Day	Thu
    Day	Fri
    Day	Sun
    so the following code would fill the Listbox2;
    Dim lngRow As Long
    
    lngRow = 2
    
    While Cells(lngRow, 1) <> ""
        If Cells(lngRow, 1) = ListBox1 Then Listbox2.AddItem Cells(lngRow, 2)
        lngRow = lngRow + 1
    Wend
    Isskint, i get satisfaction out of helping others

  3. #3
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Listbox or Combox help

    How to declare the data source? I tried using Format option to define the range but only the first Column populates

    Thanks!

  4. #4
    Registered User
    Join Date
    06-21-2013
    Location
    Wiltshire, UK
    MS-Off Ver
    365 Version 2210 Build 16.0.15726.20070
    Posts
    72

    Re: Listbox or Combox help

    Quote Originally Posted by Biplab1985 View Post
    How to declare the data source? I tried using Format option to define the range but only the first Column populates

    Thanks!
    Not sure what you mean by Format option?

    However, you need to make sure you have changed the listbox's column count property to the number of columns of data you have.

    To add more than 1 column of data per my earlier example, use the Column() method;

    Dim lngRow As Long
    
    lngRow = 2
    
    With Sheets("Sheet1")
        While .Cells(lngRow, 1) <> ""
            If .Cells(lngRow, 1) = ListBox1 Then
                ListBox2.AddItem .Cells(lngRow, 2)'add the first column
                'Column() starts at 0
                ListBox2.Column(1, ListBox1.ListCount - 1) = .Cells(lngRow, 2)' add the second column
                ListBox2.Column(2, ListBox1.ListCount - 1) = .Cells(lngRow, 2)'add the third column
            End If
            lngRow = lngRow + 1
        Wend
    End With

  5. #5
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Listbox or Combox help

    I meant Format Control of listbox. I think I am missing to declare the variable

    Could you please tell me. How do I do the below?

    data source for listbox 2 =

  6. #6
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Listbox or Combox help

    How to declare the data source? I am not using userform
    Last edited by Biplab1985; 08-15-2016 at 12:36 PM.

  7. #7
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Listbox or Combox help

    any suggestion?

  8. #8
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: Listbox or Combox help

    I am not sure about your requirements. But see the attachment if you are trying something like that.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    05-19-2015
    Location
    Karnataka, INdia
    MS-Off Ver
    MS Office 2010
    Posts
    277

    Re: Listbox or Combox help

    This should work. I am trying to build a dashboard of result using these parameters on selection from access through VBA. Would i be able to work using these listbox selection to get the result of metrics such as volume, FCR% etc.

    What i m trying to say to say is user selects from list box say year 2015 and get the volume metrics in excel from access database. The reason i m using access DB is because the data is huge for excel to hold it.

    Any suggestion would be very helpful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Fill a listbox using a combox without a loop
    By joseph.davidow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2016, 03:27 PM
  2. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  3. Update Combox with Slicer items - getting error on Combox.listcount
    By Bigkx06 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 02:47 PM
  4. [SOLVED] excel vba combox result shown in listbox
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2013, 10:23 AM
  5. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  6. Combox Box
    By rgold in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-06-2008, 01:18 PM
  7. combox question
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-17-2006, 07:00 PM

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