+ Reply to Thread
Results 1 to 2 of 2

Populate ListBox with Filtered Range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-29-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    110

    Exclamation Populate ListBox with Filtered Range

    Hi,

    I would like to fill my listbox with the date of the filtered sheet (column A)

    here's what I'm using currently

    Private Sub UserForm_Initialize()
    TextBox1.Text = Sheets("Call Stats").Range("G3").Value
    
    Dim i As Long, j As Long
      lastrow = 1
      For i = 1 To 3
          j = Sheets("Notes").Cells(Rows.Count, i).End(xlUp).Offset(1, 0).Row
          If lastrow < j Then lastrow = j
    Next i
    
    Sheets("Notes").Activate
    ListBox1.RowSource = Range("A2" & lastrow & ":" & "C" & lastrow).Address
    vntList = Sheets("Notes").Range("A2" & lastrow & ":" & "C" & lastrow)
    
    ListBox1.ColumnWidths = "60;70;200"
    TextBox2.Value = lastrow - 2
    Sheets("Call Stats").Activate
    
    End Sub
    the problem I am having is that
    1. the header is showing the first data row not my headers
    2. when the filters change, it doesnt add just the filtered

    here's a sample file: Book1.xlsmitems

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Populate ListBox with Filtered Range

    dont think you can use rowsource for what you are doing
    also i found your listbox1 was way too small to show the data you were trying to get?

    see attached possible solution
    using loop for Rng of special cells visible then loop for Listbox add item
    i tried to leave as much of your original code as possible without deleting it


    Dim lastrow As Long
    Public bDontRun As Boolean
    
    Private Sub UserForm_Initialize()
        'TextBox1.Text = Sheets("Call Stats").Range("G3").Value
        Dim rng As Range
        Dim rw As Range
        
        Dim i As Long, j As Long
        
        lastrow = Cells(Rows.Count, "A").End(xlUp).Row
        Set rng = Range("A2:A" & lastrow).SpecialCells(xlCellTypeVisible)
        
        Sheets("Notes").Activate
        
        For Each rw In rng
            ListBox1.AddItem
            For i = 1 To 3
                ListBox1.List(ListBox1.ListCount - 1, i - 1) = rw.Cells(1, i).Value
            Next i
        Next rw
        
        
        'vntList = Sheets("Notes").Range("A2" & lastrow & ":" & "C" & lastrow)
        
        ListBox1.ColumnWidths = "60;70;200"
        TextBox2.Value = rng.Count
        'Sheets("Call Stats").Activate
    
    End Sub
    Attached Files Attached Files
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ 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. HELP: Populate Worksheet ActiveX listbox using Named Range
    By nori79 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-20-2015, 09:25 AM
  2. [SOLVED] Code help: Copy only filtered range to ListBox
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 02-06-2015, 04:50 AM
  3. Populate a listbox from range
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-05-2014, 09:24 AM
  4. Populate a textbox on Userform with data from a filtered range using VBA
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2014, 04:20 AM
  5. In UserForm, how to populate a ComboBox/ListBox with a Range, defined by....
    By johnw993 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-07-2012, 11:06 PM
  6. How to Populate another Range from a Multi-Select ListBox ?
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2011, 04:49 PM
  7. how to populate listbox with named range
    By kmsoni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2011, 04:14 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