![]() |
Using Offset?
Paul,
Yes, I see what is going on now! This demo should work OK for you. it uses the built in Advanced Filter function to do all the hard work. The only tricky bit is assembling the criteria range required, with the field names in the first row and all filter values below. I've created an extra worksheet for this (deleted at the end), although you could use an existing worksheet. Note that the Advanced filter will also accept operators ,< etc. if this is useful later. Sub Demo_AdvancedFilter() Dim rngData As Range Dim wsCriteria As Worksheet Dim i As Integer, iLast As Integer, iRow As Integer Set rngData = Sheets("Data").UsedRange Application.ScreenUpdating = False 'hide sheet creation from user 'create criteria Set wsCriteria = Worksheets.Add 'get field headings wsCriteria.Range("A1").Formula = UserForm1.ListBox1.List(0) wsCriteria.Range("B1").Formula = UserForm1.ListBox1.List(1) 'get filter items for first field iRow = 2 iLast = UserForm1.ListBox11.ListCount - 1 For i = 0 To iLast If UserForm1.ListBox11.Selected(i) Then 'add this item to the filter criteria wsCriteria.Cells(iRow, 1).Formula = UserForm1.ListBox11.List(i) iRow = iRow + 1 End If Next i 'get filter items for second field iRow = 2 iLast = UserForm1.ListBox12.ListCount - 1 For i = 0 To iLast If UserForm1.ListBox12.Selected(i) Then 'add this item to the filter criteria wsCriteria.Cells(iRow, 1).Formula = UserForm1.ListBox12.List(i) iRow = iRow + 1 End If Next i 'now apply Advanced filter to copy relevant rows rngData.AdvancedFilter Action:=xlFilterCopy, criteriarange:=wsCriteria.UsedRange, copytorange:=Sheets("Results").Range("A1"), unique:=False 'delete criteria sheet Application.DisplayAlerts = False wsCriteria.Delete Application.DisplayAlerts = True End Sub Cheers, Dave "PaulW" wrote: Hopefully my follow up will provide a better explaination. Just incase not... The company produces several reports on a daily basis, for an example, this might include all files closed during the previous day. This table of data includes headers and underneath a list of all the files. The first header could be "Reference Number" and all the records will have a unique "Reference Number" the second column could be headed "Operator" and show next to each reference number who was working on this file. Other headers could include the date the file was opened, or when it was closed. If the file was closed as a success or failure, etc. A teamleader may wish to see information on a particular operator, and find out how productive they are. The idea of the userform, is to allow someone to select say the "Operator" and "Result" columns, and only have it show files with "Tom" as the operator. Essentially, the end result will look pretty much like the original data, but with the data filtered to only show "Tom" files, the extra columns deleted, the the columns kept reordered. Also, the idea is that this form would be easier to use than filtering, deleting, copying and moving data individual. This is mostly so it could be used by people who know little about excel (the kind of people that ask me on a weekly basis how to use the SUM() function correctly) |
All times are GMT +1. The time now is 10:37 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com