Placing an Autofiltered range inside an array works only once

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
439
Office Version
  1. 2016
Platform
  1. Windows
I'm currently having a problem where an auto-filtered range is only placed inside an array on the first loop but subsequent attempts to do the same despite the range filtering correctly don't work.
Code:
Set OpenWBS = Workbooks(Workbooks.Count).Worksheets(1).UsedRange
                
                strData = OpenWBS.Columns(T).Value2 'contract codes column has been added to array[T is a number]
                strData = No_Repeats(strData, strData(1, 1), UBound(strData, 1)) 'remove duplicates
                                     
                For Each element In strData
                    
                    Select Case element
                        
                        Case strData(LBound(strData)) 'skip over headers
                        
                        Case Else
                                
                            OpenWBS.AutoFilter Field:=T, Criteria1:=element, Operator:=xlFilterValues, VisibleDropDown:=false
                            'filtering worksheet for rows with the specified contract code
                                            
                            [COLOR=#ff0000]Temp_Array = OpenWBS.SpecialCells(xlCellTypeVisible).Value2[/COLOR]
                        
                            Contract_ID = element
                
                            If Not ThisWorkbook.All_Contracts.Exists(Contract_ID) Then
        
                                    'if the Contract_ID Key does not exist then create a new dictionary
                                    
                                    Set C_Dict = New Scripting.Dictionary 'create a new dictionary with the Contract_ID as a key
                                    
                                    ThisWorkbook.All_Contracts.Add Contract_ID, C_Dict
        
                                    'add the new dictionary to the orginal
                            End If
        
                            Set C_Dict = ThisWorkbook.All_Contracts.Item(Contract_ID)       'dictionary within a dictionary
                         
                            For X = LBound(Temp_Array, 1) + 1 To UBound(Temp_Array, 1) 'offset by 1 to skip headers in visible range
                            
                                D = Convert_Date(Temp_Array(X, 2)) 'the 2nd element corresponds with a date string--> convert to serial date
                        
                                C_Dict.Add D & "-" & Temp_Array(X, 1), WorksheetFunction.Index(Temp_Array, X, 0)
                                'key is SerialDate-Name
                            Next X
                            
                        OpenWBS.AutoFilter Field:=T 'clear the autofilter from the contract column
                        
                        'Erase Temp_Array
                        
                    End Select
                               
                Next element
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top