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 8354931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:42:28+00:00 2026-06-09T09:42:28+00:00

I am presently working with data from a mainframe, not unlike the data presented

  • 0

I am presently working with data from a mainframe, not unlike the data presented here. In this case, all I have are strings akin to 100-AAA for my criteria and for my target data set. I have searched for a similar solution, but I have not found a direct filter by range question for VBA on SO.

I am attempting to filter a large dataset based on a range of criteria. Originally, I started playing with collections in separate classes/subroutines, but then I compressed to the use of ranges within a single subroutine, as follows:

Sub FilterTest1()

Dim RngOne As Range
Dim LastCell As Long

Sheets("Criteria").Activate
Sheets("Criteria").Select
Range("A1").Select

LastCell = Application.WorksheetFunction.CountA(ActiveSheet.Range("A:A"))

Set RngOne = ActiveSheet.Range("A2:A" & LastCell)

Sheets("Sheet 1").Activate
Sheets("Sheet 1").Select

With ActiveSheet
    If .FilterMode Then
    .ShowAllData
    End If
End With

Columns("A:A").Select
Selection.AutoFilter
ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:=RngOne, Operator:=xlOr

End Sub

Unfortunately, my range of cells does not filter the data, even when using criteria such as Operator:=xlOr – it just displays the very last cell value used for the criteria. The VBA code does not fail – it just does not filter properly based on the range.

I feel certain that there exists a simple solution, but I cannot quite see it.

  • 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-09T09:42:29+00:00Added an answer on June 9, 2026 at 9:42 am

    Your current line:

    ActiveSheet.Range("A:A").AutoFilter Field:=1, Criteria1:=RngOne, Operator:=xlOr
    

    is trying to filter your first field by a Range object, not by each value in the range.

    I’ve provided one way to do this below, by loading your values into an array and then passing the array to the filter criteria.

    A few points worth noting to help you (and anyone else in the future):

    • I learned of the correct syntax to filter on a selection of objects by using the macro recorder.
    • This site helped me learn about the array trick: Pass Array to Filter Criteria
    • I also cleaned up your code to make it more efficient and faster, by getting rid of useless select statements and such. (Not a big deal for this little bit of code, but getting out of that practice will help you for bigger projects!)

    Code Below:

    Sub FilterTest1()
    
    Dim RngOne As Range, cell As Range
    Dim LastCell As Long
    Dim arrList() As String, lngCnt As Long
    
    With Sheets("Criteria")
        LastCell = .Range("A" & Sheets("Criteria").Rows.Count).End(xlUp).Row
        Set RngOne = .Range("A2:A" & LastCell)
    End With
    
    'load values into an array
    lngCnt = 0
    For Each cell In RngOne
        ReDim Preserve arrList(lngCnt)
        arrList(lngCnt) = cell.Text
        lngCnt = lngCnt + 1
    Next
    
    
    With Sheets("Sheet 1")
    
        If .FilterMode Then .ShowAllData
    
        .Range("A:A").AutoFilter Field:=1, Criteria1:=arrList, Operator:=xlFilterValues
    
    End With
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON file and i have to read data from this file
I have been working on a project which is about data copy from one
I am working on Vb6. And I have a Listview which displays data from
I have this same problem, but the solution presented isn't working, nor is any
Presently Iam working in finding disparity of stereo pair. I have got a situation
I'm currently working on a project where we have a large data warehouse which
I'm working on a project which involves aggregating data from a variety of sources
We have service that's working with small to large sets of data (document generation),
I'm working on a system for graphically querying data from a database of parasite
I'm using AFNetworking with AFHTTPRequestOperation to pull XML data from a webservice. This is

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.