我看到了几种不同的解决方案,可以绕过excel中的过滤器的2个通配符限制(特别是将答案发布在here上,但是我很难理解它们的作用。实现是只使用基本countif公式计算单元格中每个条件的实例数,如果它是0,则宏将隐藏该行。
With ws1
ColumnOne = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, lastColumn).End(xlUp).Row
ColumnTwo = ColumnOne - 1
If ws2.Application.WorksheetFunction.CountA("D47:D61") <> 0 Then
For i = 1 To LastRow
If .Cells(i, ColumnTwo).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
ElseIf ws2.Application.WorksheetFunction.CountA("E47:E61") <> 0 Then
For i = 1 To LastRow
If .Cells(i, ColumnOne).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
Else
Exit Sub
End If
End With
上面的代码是我用来处理此问题的代码。作为参考,在单独的工作表(ws2)上有两列条件可以更改/完全为空。然后,上面的代码通过查看哪一个不为空来检查应使用哪些列(ws2上的D在ws1上使用ColumnTwo,ws 2上的E在ws1上使用ColumnOne),然后查看哪一个不为空,然后开始检查ws1行上的列行以查看是否存在任何条件。如果不存在任何条件(单元格值= 0),则应隐藏该行。
使用D或E的检查似乎无效。即使ws2上D47:D61中的所有单元格都为空,它仍在if语句内运行,而不是移至E47:E61。关于我应该在此处尝试更改的任何想法?
答案 0 :(得分:1)
我修改了您的代码以确保声明所有变量。
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
root: {
sideMenu: {
left: {
component: {
....
}
},
}
}
});
});
答案 1 :(得分:0)
下面的代码现在似乎可以正常工作:
With ws1
ColumnTwo = .Cells(1, .Columns.Count).End(xlToLeft).Column
LastRow = .Cells(.Rows.Count, lastColumn).End(xlUp).Row
ColumnOne = ColumnTwo - 1
With ws2
Set aDataRange = ws2.Range("D47:D61")
Set pDataRange = ws2.Range("E47:E61")
If Application.WorksheetFunction.CountA(aDataRange) <> 0 Then
MsgBox ("ColumnOne")
With ws1
For i = 1 To LastRow
If .Cells(i, ColumnOne).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
End With
ElseIf Application.WorksheetFunction.CountA(pDataRange) <> 0 Then
MsgBox ("ColumnTwo")
With ws1
For i = 1 To LastRow
If .Cells(i, ColumnTwo).Value = 0 Then
.Rows(i).EntireRow.Hidden = True
End If
Next i
End With
Else
Exit Sub
End If
End With
End With
为什么我需要分别定义ws2上D47:D61 / E47:E61的范围区域?为什么“ ws2.Application.WorksheetFunction.CountA(“ Range”)“不适用于ws2上的范围,即使该范围包含在“ With ws2”中?