有没有办法修改此代码,以便它只隐藏/取消隐藏特定范围内的行,如行21:89?
Sub HideLLRows() '此子联合/隐藏EIRP LL中的空白行
Application.ScreenUpdating = False
Dim i As Long
Dim EIRPLL As Worksheet
Dim NewState As VbTriState
Dim dat As Variant
Dim rws As Range
Dim LastRow As Long
Set EIRPLL = Sheets("EIRP LL")
With EIRPLL.UsedRange
LastRow = .Rows.Count - .Row + 1 ' in case used range doesn't start at row 1
dat = .Columns(2).Resize(LastRow, 1)
End With
NewState = vbUseDefault
With EIRPLL
For i = 6 To LastRow
If dat(i, 1) = "" Then
If NewState = vbUseDefault Then
NewState = Not .Rows(i).Hidden
End If
If rws Is Nothing Then
Set rws = Cells(i, 1)
Else
Set rws = Union(rws, Cells(i, 1))
End If
End If
Next
End With
rws.EntireRow.Hidden = NewState
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
您可以使用以下内容:
hStatus = Rows("21:89").Hidden
If hStatus = False Then hStatus = True Else hStatus = False
Rows("21:89").Hidden = hStatus
您需要检查隐藏属性是什么,将其设置为变量,然后将变量切换到相反的位置并使用它来设置隐藏属性。