+ Reply to Thread
Results 1 to 10 of 10

Filter Data based on a set of values

Hybrid View

  1. #1
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    Filter Data based on a set of values

    I have been utilizing an array formula for a while to filter out specific data that I am looking for, however, those arrays are causing some delays due to the amount of calculation that is going into each one. Yes I know that I can use a formula to get the job done but for simplicities sake i'd rather be able to run a macro that can check the fluctuating list and be able to output that same data without having to drag down a bunch of arrays that may not even run.

    As you will see in the spreadsheet, there are a set of 4 columns, I want the second set of data (to the right) to have only data that is for "ACD" AFTER "RING", which I have included in an example above where the output should be.

    Book2.xlsm

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Filter Data based on a set of values

    Hello,

    Would this do the trick?
    Sub hsv()
    With Sheets("sheet1").Range("A3").CurrentRegion
       .Parent.Range("G10").CurrentRegion.ClearContents
       .AutoFilter 3, Array("ACD", "AFTER", "RING"), 7
       .Copy Sheets("sheet1").Range("G10")
       .AutoFilter
    End With
    End Sub
    Kind regards, Harry.

  3. #3
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    Re: Filter Data based on a set of values

    Quote Originally Posted by HSV View Post
    Hello,

    Would this do the trick?
    Sub hsv()
    With Sheets("sheet1").Range("A3").CurrentRegion
       .Parent.Range("G10").CurrentRegion.ClearContents
       .AutoFilter 3, Array("ACD", "AFTER", "RING"), 7
       .Copy Sheets("sheet1").Range("G10")
       .AutoFilter
    End With
    End Sub
    That almost does the trick. While it does copy each RING and ACD event I'm wanting it to only pull the first ACD after each RING but does not need to include each one. Much more like the example that I posted.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Filter Data based on a set of values

    Mr. HSV what number 7 at the end of this line?
    .AutoFilter 3, Array("ACD", "AFTER", "RING"), 7
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  5. #5
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Filter Data based on a set of values

    It stands for
    xlFilterValues

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Filter Data based on a set of values

    Try this.
    Attached Files Attached Files
    Last edited by skywriter; 05-25-2015 at 03:47 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  7. #7
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Filter Data based on a set of values

    Okay, that I have missed.
    Without copy something faster.

    Sub FilterData()
    Dim sn, arr, cl As Range, i As Long, n As Long
    With Sheets("sheet1")
      sn = .Range("a3").CurrentRegion
      ReDim arr(UBound(sn), 3)
     For i = 1 To UBound(sn) - 1
        If UCase(sn(i, 3)) = "RING" And UCase(sn(i + 1, 3)) = "ACD" Then
            arr(n, 0) = sn(i + 1, 1)
            arr(n, 1) = sn(i + 1, 2)
            arr(n, 2) = sn(i + 1, 3)
            arr(n, 3) = sn(i + 1, 4)
            n = n + 1
        End If
       Next i
         With .Range("G10")
            .CurrentRegion.ClearContents
            .Resize(, 4) = Array("Date", "Time", "State", "Length")
            .Offset(1).Resize(UBound(arr), 4) = arr
        End With
    End With
    End Sub

  8. #8
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    Re: Filter Data based on a set of values

    Quote Originally Posted by HSV View Post
    Okay, that I have missed.
    Without copy something faster.

    Sub FilterData()
    Dim sn, arr, cl As Range, i As Long, n As Long
    With Sheets("sheet1")
      sn = .Range("a3").CurrentRegion
      ReDim arr(UBound(sn), 3)
     For i = 1 To UBound(sn) - 1
        If UCase(sn(i, 3)) = "RING" And UCase(sn(i + 1, 3)) = "ACD" Then
            arr(n, 0) = sn(i + 1, 1)
            arr(n, 1) = sn(i + 1, 2)
            arr(n, 2) = sn(i + 1, 3)
            arr(n, 3) = sn(i + 1, 4)
            n = n + 1
        End If
       Next i
         With .Range("G10")
            .CurrentRegion.ClearContents
            .Resize(, 4) = Array("Date", "Time", "State", "Length")
            .Offset(1).Resize(UBound(arr), 4) = arr
        End With
    End With
    End Sub
    Works like a charm! Thanks for that!

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Filter Data based on a set of values

    Quote Originally Posted by klturi421 View Post
    Works like a charm! Thanks for that!
    It looks like my solution in post #5 did what you asked, but you seemed to have ignored it. Of course I guess I should get partial credit since the person who wrote the solution you chose took the name of my sub procedure and used it instead of making up their own.

  10. #10
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    Re: Filter Data based on a set of values

    Quote Originally Posted by skywriter View Post
    It looks like my solution in post #5 did what you asked, but you seemed to have ignored it. Of course I guess I should get partial credit since the person who wrote the solution you chose took the name of my sub procedure and used it instead of making up their own.
    I honestly did not see your reply. Not due to looking past it but by the time I updated my post you posted yours and I didn't see it until after HSV already made a change to the VB. I do appreciate everyone's input. I will likely make use of both of them to be honest.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Filter data based on two variables(between two values)
    By ROHAN999 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-10-2013, 05:09 AM
  2. Filter Data based on values in another workbook.
    By yoom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2013, 08:28 PM
  3. Filter & Print based on values in a range
    By Pergo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2013, 02:39 PM
  4. Second Advanced Filter does not work based on the data generated from the filter
    By mucc1928 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2011, 02:42 PM
  5. Changing Values Based Upon Filter
    By michaelk68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2011, 11:34 AM

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