|
- Sub completeedit()
- Dim ws As Worksheet
- Dim cell As Range, hideRanges As Range
- Dim found(1 To 3) As Boolean
-
- Application.ScreenUpdating = False
- Application.Calculation = xlCalculationManual
-
- ' 优化 Sheet7 搜索逻辑
- For Each cell In Sheet7.Range("F7:F37")
- Select Case True
- Case InStr(1, cell.Value, "确权", vbTextCompare) > 0: found(1) = True
- Case InStr(1, cell.Value, "确权外", vbTextCompare) > 0: found(2) = True
- Case InStr(1, cell.Value, "其他", vbTextCompare) > 0: found(3) = True
- End Select
- If found(1) And found(2) And found(3) Then Exit For
- Next cell
-
- ' 隐藏相应工作表的空行
- If found(1) Then HideRowsBasedOnCondition Sheet3, "D6:D35,D39:D68", "=""", True
- If found(2) Then HideRowsBasedOnCondition Sheet4, "D6:D35,D39:D68", "=""", True
- If found(3) Then HideRowsBasedOnCondition Sheet5, "D5:D25", "=""", True
- HideRowsBasedOnCondition Sheet6, "D6:D300", "=""", True
- HideRowsBasedOnCondition Sheet7, "G7:G37", "=""", True
- HideRowsBasedOnCondition Sheet2, "E8:E11", "<=0", False
-
- Application.ScreenUpdating = True
- Application.Calculation = xlCalculationAutomatic
- End Sub
- Sub HideRowsBasedOnCondition(ws As Worksheet, rangeAddress As String, condition As String, useCountA As Boolean)
- Dim rng As Range, cell As Range, hideRanges As Range
-
- For Each rng In ws.Range(rangeAddress)
- If useCountA Then
- If Application.WorksheetFunction.CountA(rng) = 0 Then
- If hideRanges Is Nothing Then
- Set hideRanges = rng.EntireRow
- Else
- Set hideRanges = Union(hideRanges, rng.EntireRow)
- End If
- End If
- Else
- If Evaluate(rng.Address & condition) Then
- If hideRanges Is Nothing Then
- Set hideRanges = rng.EntireRow
- Else
- Set hideRanges = Union(hideRanges, rng.EntireRow)
- End If
- End If
- End If
- Next rng
-
- If Not hideRanges Is Nothing Then hideRanges.Hidden = True
- End Sub
复制代码
|
|