Consulting

Results 1 to 4 of 4

Thread: Add multiple filtered row data to ListBox

  1. #1
    VBAX Regular
    Joined
    Feb 2015
    Posts
    36
    Location

    Add multiple filtered row data to ListBox

    Hi guys,

    I am a bit stuck, and hope you will help me.

    I am trying to add a range of filtered data to a ListBox. Currently, my method adds the first filtered row data, but not any additional rows if there are multiple rows in my filtered data.

    Detail:

    I have a search function that filters my data based on column 1.
    When you dbl click on the suggested search matches in ListBox3, it updates the UserForm with the filtered row data from Sheet1. It also updates ListBox1 with the data in range E2- I2.

    HOWEVER: I would like to update ListBox1 with all the data of how many rows there might be in my active filter for the range E2+ - I2+

    I named the range: RecordData - this might be an option?

    Perhaps some type of Loop to this code:

    With ListBox1
    .ColumnCount = 6
    .AddItem
    
    .Column(0, 0) = Sheets("Sheet1").Cells(FirstRow, 5).Value
    .Column(1, 0) = Sheets("Sheet1").Cells(FirstRow, 6).Value
    .Column(2, 0) = Sheets("Sheet1").Cells(FirstRow, 5).Value
    .Column(3, 0) = Sheets("Sheet1").Cells(FirstRow, 6).Value
    .Column(4, 0) = Sheets("Sheet1").Cells(FirstRow, 5).Value
    .Column(5, 0) = Sheets("Sheet1").Cells(FirstRow, 6).Value
    
    End With
    i have attached my sample workbook.

    Thank you VERY much!
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Basically (mutatis mutandis):

    Sub M_snb()
      with sheet1.cells(1).currentregion
        .autofilter 1, "filtertext"
        .offset(1).copy sheet1.cells(1,100)
        .autofilter
      end with
    
      Listbox1.List=sheet1.cells(1,100).currentregion.value
      Listbox1.columncount=ubound(listbox1.list,2)+1
      sheet1.cells(1,100).currentregion.clearcontents
    End Sub

  3. #3
    VBAX Regular
    Joined
    Feb 2015
    Posts
    36
    Location
    hi snb

    Thanks for looking at this for me. It really has me stumped.

    Where do I put the code?

    locus ubi codicem

  4. #4

Posting Permissions

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