Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

excel - Trying to create a range within a filtered range (trying to create a second filter)

I'm trying to create a range within a filtered range. My code starts out by filtering the first set of data. Once this data is filtered (based on criteria in column G), I am trying to a create a range which would then be sorted based on date criteria to be sorted once more. I'm currently not sure how to re-create such parameters like "first row" and "last row" after the first set of filtering, but here's what I have so far. I cannot filter these at the same time, just for independent reasons.

ProjectSpreadsheet.Range("A1").AutoFilter Field:=7, Criteria1:=criterion

Dim ProjectCodes As Variant

For Each ProjectCodes In Array("teacup", "plate", "fork", "spoon", "table", "chair", "knife", "fork", "soda", "TEA")
    FilterRows ProjectCodes
        
                   

        With ProjectSpreadsheet
            
            'Loop until to the last row
            Dim LastRowProjectSpreadsheet As Long
            LRProjectSpreadsheet = .Range("A" & Rows.Count).End(xlUp).Row
        
            'Now we need to set a value to the relevant range. This is the range
            'before the data gets sorted
            Dim rRange As Range
            Set rRange = .Range("A2:O" & LRProjectSpreadsheet)
        
            'After sorting, we will end up with several data rows for
            'which we will need to sort from. Now that we have a filtered table,
            'we would then need to created a variable for our new filtered range
            Dim fltrdRng As Range
            Set fltrdRng = rRange.SpecialCells(xlCellTypeVisible)
            

Here's where I'm stuck at where it becomes harder for me to filter a second time. The code above works just fine.

            Dim aCell As Range
            
            Dim DateRange As Range
            Dim DateRangeLastRow As Long
            DateRangeLastRow = Range("L" & Rows.Count).End(xlUp).Row
            Set DateRange = fltrdRng.Range("L" & DateRangeLastRow).SpecialCells(xlCellTypeVisible)
            
            For Each aCell In DateRange
                Debug.Print aCell
            Next

' For Each aCell In fltrdRng ' Debug.Print aCell ' Next End With

Next ProjectCodes
question from:https://stackoverflow.com/questions/65660299/trying-to-create-a-range-within-a-filtered-range-trying-to-create-a-second-filt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...