excel vba - Dynamic filters (different strings) for multiple sheets (different sheets in the same workbook) VBA- Solved -


I am quite new to VBA and I am still in the learning stage

I have a There is a letter designated in the workbook where there are different fields in the column AI which I am filtering on. In this case, it will be 'grace'. For this I managed to tweak some sections of Google and code and the code looks like this

  sub-dynamicFilter () SearchCol = "Type" SearchFor = "Anwendung" set rng1 = ActiveSheet.UsedRange. Select Find (SearchCol ,, xlValues, xlWhole) range ("A1") Selection.AutoFilter Selection.AutoFilter field:. = Rng1.Column, Criteria1: = SearchFor End Sub  

Now I have some other sheets in the workbook where I need to filter them according to other strings in the column 'Resorsion' above in AI With the code mentioned above, I can only apply it for active sheet, not the whole work book

if I define dimming it as a worksheet and then in it Run for loop. Then it filters all sheets in filter form with 'Unwandung' as the filter criteria, and the filter criteria for some sheets varies.

  ActiveWorkbook.Worksheets ws.Activate SearchCol = In the "Type" searchFor sub DynamicFilter () for the dim Ws worksheet set = "Anwendung" for each WS rng1 = ActiveSheet.UsedRange.Find (SearchCol ,, .xlValues, xlWhole) range ("A1") Select Selection .AutoFilter Selection.AutoFilter field: = rng1.Column, Criteria1: = SearchFor next ws end sub  

How can I do all I need I define multiple filters for multiple sheets, Filter 1 for 'Sheet1' and 'Filter 2': 'Allowance': 'Resurrection' for Sheet 2, as a filter for another sheet and so on.

I am truly grateful if any of you can help me.

Edit - Hull - Record the macro, execute it and rotate it in small amounts, finally managed to solve this issue

  sheet ("Anwendungen ") Select ActiveWindow.SmallScroll ToRight:. = 15 ActiveSheet.Range. ("$ A $ 1: $ AZ $ 10,637") Auto Filter Field: = 35, Criteria1: = _ "Anwendung" Sheet ("Ressourcen") Select ActiveWindow.SmallScroll ToRight:. = 16 ActiveSheet.Range ("$ A $ 1: $ AZ $ 10,637") Auto Filter Field:. = 35, Criteria1: = array (_ "Gebäude" "operator: XL filter value       

SearchFor variable

 

Design> Sub DynamicFilter () In the ActiveWorkbook, design the worksheet for each section. Find worksheets findcall = "Type" SearchFor = ws.Name Set rng1 = ws.UsedRange.Find (SearchCol ,, xlValues, xlWhole) Autofilter ws Range ("A1"). AutoFilter field: = rng1.Column, Criteria1: = Sea RchFor Next ws End sub

If there is a cell for the SearchFor criteria, you can assign the value of the cell in such a way as:

< Pre> SearchFor = ws.Range ("AI1")

Comments