excel - 不要调整隐藏行的大小
问题描述
我想让一个范围内的所有行都具有一定的高度,除了隐藏的行。一旦我的代码到达.SpecialCells (xlCellTypeVisible)
它就会跳转到 a Private Sub()
,然后返回并.RowHeight = 12
更改我的所有行,包括隐藏的行。如何防止它调整隐藏的行?
Sub CreateSched()
Worksheets("Schedule").Activate
Sheets("Schedule").Unprotect
Dim t As Range, u As Range
Set u = Range("F6:F282")
Application.ScreenUpdating = False
For Each t In u
If Not IsEmpty(t.Value) And t = 0 Then
t.EntireRow.Hidden = True
ElseIf t > 0 Then
t.EntireRow.Hidden = False
End If
Next t
Application.ScreenUpdating = True
Columns("B:AA").AutoFit
With Worksheets("Schedule").Range("E1:E304")
.SpecialCells (xlCellTypeVisible)
.RowHeight = 12
End With
Sheets("Schedule").Protect
End Sub
解决方案
试试这个 - 一些避免选择/激活的建议(通常这不是必需的)
Sub CreateSched()
Dim t As Range
With Worksheets("Schedule")
Application.ScreenUpdating = False
.Unprotect
For Each t In .Range("F6:F282").Cells
If Not IsEmpty(t.Value) And t = 0 Then
t.EntireRow.Hidden = True
ElseIf t > 0 Then
t.EntireRow.Hidden = False
End If
Next t
On Error Resume Next '<< in case no visible rows
.Range("E1:E304").SpecialCells(xlCellTypeVisible).RowHeight = 12
On Error Goto 0 'stop ignoring errors
.Columns("B:AA").AutoFit
.Protect
Application.ScreenUpdating = True
End With
End Sub
推荐阅读
- python - 使用 Python 在 MySQL 上执行 upsert 操作
- r - R中传单中聚类标记的聚合加权线串
- angular - RXJS:返回嵌套的 observables
- python - python函数计算图像中每个点到图像中心的欧几里得距离
- python - 我的正则表达式(re.sub)、重音符号(latin-1 模式)有什么问题?
- python - UnboundLocalError:分配前引用的局部变量“Y_p”
- java - 如何比较 E 元素
- python - 与 Map 相比,什么时候使用 Set 更合乎逻辑?
- reactjs - React Native useEffect Hooks 和 React Navigation setParams 在加载时不会更新
- javascript - React Native - 如何在 FlatList 属性上使用导航?