?
Solved

List box - only visible entries

Posted on 2012-03-21
4
Medium Priority
?
196 Views
Last Modified: 2012-03-21
Hi,

I have filtered a list for unique entries only, but my code for bring that list into a list box still picks up the hidden rows

Can i change the below code to only import visible entries

Thanks
Seamus

Private Sub UserForm_Activate()

Dim j As String
   
    j = 2
    Do While Sheets("Sheet1").Cells(j, 1).value
        j = j + 1
    Loop
   
    Me.ListBox1.RowSource = "Sheet1!Q2:Q" & (j - 1)



End Sub
0
Comment
Question by:Seamus2626
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 37746754
0
 
LVL 18

Accepted Solution

by:
p912s earned 2000 total points
ID: 37746923
This will get you your unique list without the filter.

Private Sub UserForm_Activate()
    Dim cell As Range
    Dim tempList As Variant: tempList = ""
    For Each cell In Range("Q2:Q" & Range("Q65536").End(xlUp).Row)
        If cell.Value <> "" Then
            If InStr(1, tempList, cell.Value) = 0 Then
                If tempList = "" Then tempList = Trim(CStr(cell.Value)) Else tempList = tempList & "|" & Trim(CStr(cell.Value))
            End If
        End If
    Next cell
    Me.ListBox1.List = Split(tempList, "|")
End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 37746939
Cheers, thats the one i needed!

Seamus
0
 
LVL 18

Expert Comment

by:p912s
ID: 37746988
Glad to help!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question