Results 1 to 4 of 4

Only copy visible data to ListBox

Threaded View

  1. #1
    Forum Contributor onmyway's Avatar
    Join Date
    09-03-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2013
    Posts
    386

    Only copy visible data to ListBox

    Hi guys,

    i hope you can help me.

    I am trying to copy a range of filtered data to a ListBox, but am struggling with the parameters.
    1. How can I edit this sub to only copy the visible data of my Range ("RecordData");
    2. Not copy the first row - headers;
    3. Not copy empty rows in this range?


    Sub updateListBox()
    
        Dim ws As Worksheet
        Dim rng As Range
        Dim i As Long, j As Long, rw As Long
        Dim Myarray() As String
    
        '~~> Change your sheetname here
        Set ws = Sheets("Sheet1")
    
        '~~> Set you relevant range here
        'Set rng = ws.Range("E2:J5")
        
        Set rng = ws.Range("RecordData")
    
            With Me.ListBox1
            .Clear
            .ColumnHeads = False
            .ColumnCount = rng.Columns.Count
    
            ReDim Myarray(rng.Rows.Count, rng.Columns.Count)
    
            rw = 0
    
            For i = 1 To rng.Rows.Count
                For j = 0 To rng.Columns.Count
                    Myarray(rw, j) = rng.Cells(i, j + 1)
                Next
                rw = rw + 1
            Next
    
            .List = Myarray
    
            '~~> Set the widths of the column here. Ex: For 5 Columns
            '~~> Change as Applicable
            .ColumnWidths = "75;75;75;75;75;75"
            .TopIndex = 0
        End With
    
    'End Sub
    Thank you for all your help!
    Last edited by onmyway; 02-06-2015 at 04:55 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel VBA to copy visible filtered data from from one worksheet to another
    By rahul1023 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2013, 09:00 PM
  2. Error checking of visible filtered data - Display text in textbox if no data visible
    By cocobean in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 12:58 AM
  3. Hidden/Visible sheets in listbox
    By DRoberts in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2009, 08:18 AM
  4. Replies: 1
    Last Post: 10-08-2005, 05:05 PM
  5. listbox.visible = false question
    By Oreg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-20-2005, 10:43 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