|
不知道有没有人有这个需求。以前尝试过,没写出来。今天突然有了灵感才写出来的,这个版本很容易看出思路,没有做过多的优化
- Function GetRangeOutsideRange_(rng As Range) As Range
- '返回rng以外的所有单元格区域
- On Error Resume Next
- 'Cells.ClearFormats
- Dim r As Range, rngTemp As Range, ret As Range
- rng.Application.ScreenUpdating = False
- For Each r In rng.Areas
- r.EntireRow.Hidden = True
- Set rngTemp = rng.Application.Cells.SpecialCells(xlCellTypeVisible)
- r.EntireRow.Hidden = False
-
- r.EntireColumn.Hidden = True
- Set rngTemp = rng.Application.Union(rngTemp, rng.Application.Cells.SpecialCells(xlCellTypeVisible))
- r.EntireColumn.Hidden = False
-
- If ret Is Nothing Then
- Set ret = rngTemp
- Else
- Set ret = rng.Application.Intersect(ret, rngTemp)
- End If
- Next
- rng.Application.ScreenUpdating = True
- Set GetRangeOutsideRange_ = ret
- End Function
复制代码
|
|