Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:13:15+00:00 2026-06-15T17:13:15+00:00

First post on here, so I hope I’m clear enough. I have a table

  • 0

First post on here, so I hope I’m clear enough.

I have a table on a worksheet that I am working with. I’ve passed the listObject to a class, which can return various bits of data from it. I’d like to retrieve a unique list, by filtering against a specified column heading.

My question is this:

Can I return a range containing all the rows, once filtered, without looping through the entire, unfiltered range manually?

My current code loops through the (unfiltered) range, looking for unique entries as below. It’s taking a noticeable amount of time on my test worksheet, so don’t think it’ll be viable for the operational example.

Public Function returnUniqueList(col As String) As Collection
' get unqiue lists from the table.  Useful for things like LCPs or ballast types
' returns as list of strings

Dim i As Integer
Dim r As Excel.Range
Dim reqCol As Integer
Dim tempString As String
' collection of strings with the unique values
Dim retString As New Collection

reqCol = returnColId(col)

On Error GoTo errorCatch

' collect the unique values
For Each r In pLO.Range.rows

    If Not InCollection(retString, r.Cells(1, reqCol)) Then
        ' add to the collection, including the key
        If r.Cells(1, reqCol) <> "" Then
           retString.Add r.Cells(1, reqCol), r.Cells(1, reqCol)
        End If
    End If
Next r

Set returnUniqueList = retString
Exit Function
errorCatch:
  MsgBox "Error returning unique list: " + Err.Description

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:13:16+00:00Added an answer on June 15, 2026 at 5:13 pm

    So after some messing around with various in-built excel/VBA functionality, I’ve settled on advanced filters. One of the issues I had, was that while I filtered on one column, I wanted to return the filtered table to the calling piece of code. The above function now looks like this:

    Public Function returnUniqueList(col As String, searchTerm As String) As Excel.range
    ' get unique lists from the table.  Useful for things like LCPs or ballast types
    ' returns as excel.range
    
    Dim reqCol As Integer
    
    On Error GoTo errorCatch
    
    reqCol = returnColId(col)
    Dim critRange As String
    Dim cr As Excel.range
    
    
    critRange = "=""=" + searchTerm + "*"""
    
    pWkSht.Cells(1, 1000) = col
    pWkSht.Cells(2, 1000) = critRange
    
    Set cr = pWkSht.range(pWkSht.Cells(1, 1000), pWkSht.Cells(2, 1000))
    ' filter for unique entries on this column
    pLO.range.Columns(reqCol).Select
    pLO.range.Columns(reqCol).AdvancedFilter Action:=xlFilterInPlace, Unique:=True, CriteriaRange:=cr
    
    
    Set returnUniqueList = pLO.range.SpecialCells(xlCellTypeVisible).EntireRow
    pWkSht.Cells(1, 1000) = Empty
    pWkSht.Cells(2, 1000) = Empty
    Exit Function
    
    errorCatch:
    MsgBox "Error returning unique list: " + Err.Description
    
    End Function
    

    The tricky thing I found was then working on the range in the calling function. I found that excel ranges can contain ‘areas’. This is due to the way excel works with contiguous data. So in the calling function, I had to iterate through the areas in the returned ranges. This does add a level of overhead into the original calling function that I had hoped to avoid (I wanted to return a single range, with a single area that could easily be iterated through).

    The most reliable method I found of iterating through the range/areas returned from the above is based around this snippet, which I use in loads of places in one fashion or another (different columns being pulled from the table, etc:

    Set devices = edh.returnUniqueList("DaliCct", lcp)
    ' filter by the requested LCP
    
    'clear down the dali ccts box
    daliCctsListBox.Clear
    
    ' cycle through the returned areas, retrieving the relvant info
    For i = 1 To devices.Areas.Count
        For rowInd = 1 To devices.Areas(i).rows.Count
            Dim r As Excel.range
            For Each r In devices.Areas(i).rows(rowInd)
    
             If (r.Cells(daliCctColId) <> "") And (r.Cells(daliCctColId) <> "DaliCct") Then
                 daliCctsListBox.AddItem r.Cells(daliCctColId)
                 bAdded = True
             End If
            Next r
        Next rowInd
    Next i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First post here, so I hope it is detailed enough. While developing an Iphone
First post here, so I hope this is enough detail. I started using freebase-python
This is my first post here and I really hope, that someone could help
My first post here...I hope that I don't brake any rules and if I
This is my first post here and I hope that someone will be able
My first post here, so i hope this is the right area. I am
This is my first time here so I hope I post this question at
My first post here :) I have a summer job doing a bit of
This is my first post here. I have a problem. I need to take
first post here and hopefully relevant to many people. I'm working on writing integration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.