【发布时间】:2012-08-18 00:03:36
【问题描述】:
我进行了广泛的搜索,发现了大量关于排列的信息,但我想不出一个好的方法来调整它们。这令人沮丧,因为我认为答案并不难,但我似乎无法靠自己到达那里。
我正在尝试将包含选择标准的单元格范围转换为高级过滤器可以读取的范围。选择标准的范围如下所示:
问题是,高级筛选器将每一行作为单独的筛选器集进行评估。逻辑看起来像这样:
[awake AND bob AND cat AND earth AND yes] OR [sleeping AND sally AND dog AND earth AND yes] OR ... OR [martha].
这是高级过滤器应该工作的方式,但我需要它像自动过滤器一样工作,我会遍历每个字段并检查每个过滤器条件。逻辑应该是这样的:
[awake OR sleeping] AND [bob OR sally OR george OR martha] AND [cat OR dog OR bird] AND [earth] AND [alive]
阅读文档和多个论坛后,我能找到的唯一方法是在单独的行上生成每个可能的选择标准组合。新的选择标准范围应如下所示:
我已经通过手动设置选择标准范围对此进行了测试,它可以正常工作,但我无法找出自动化它的代码。这是我到目前为止所做的 - 开始还可以,但很快就会开始重复并丢失某些排列:
If UBound(numRows) > 1 Then
With Worksheets("fltr")
.Range(.Cells(4, 1), .Cells(4, UBound(numRows))).Copy Destination:=Worksheets("afltr").Range("A1")
End With
'Determine number of rows needed for Advanced filter
numPermute = numRows(1)
For dstCol = 2 To UBound(numRows)
numPermute = numPermute * numRows(dstCol)
Next dstCol
'Copy all permutations to advanced filter
For dstCol = 1 To UBound(numRows)
If thisRow > numRows(dstCol) Then
thisRow = 2
For thisGrp = 1 To numRows(dstCol)
andSpltPos = 1
For numRepeat = 1 To numPermute / numRows(dstCol)
sbstFltrItms = Worksheets("fltr").Cells(4 + thisGrp, dstCol).Value 'MOD Problem?
Worksheets("afltr").Cells(thisRow, dstCol).Value = sbstFltrItms
thisRow = thisRow + 1
Next numRepeat
Next thisGrp
Next dstCol
End If
非常感谢您对生成正确排列或使高级过滤器以其他方式工作的帮助。
【问题讨论】:
标签: vba excel filter permutation